Silverlight BusyIndicator : Higher Z-Index than all ChildWindows

百般思念 提交于 2019-12-09 02:18:29

As you've got your application root visual set to the busy spinner you will not be able to change the Z-Index so it is higher than the ChildWindow. Your best bet would be to extend the ChildWindow control and add a busy spinner into it and then set IsBusy on the ChildWindow rather the root visual when you have windows open.

Hope that helps.

You don't have to subclass ChildWindow to be able to use BusyIndicator over ChildWindows. I am using following solution:

1-Define Global ContentTemplate for all ChildWindow Controls. Bind IsBusy property to "IsBusy" of ChildWindow's datacontext.

<Style TargetType="sdk:ChildWindow">
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <toolkit:BusyIndicator IsBusy="{Binding IsBusy}">
                        <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </toolkit:BusyIndicator>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

2- Define a singleton class which is ready during silverlight application is running. I picked App class for this. Implement INotifyPropertyChanged interface to auto refresh all IsBusy binders. Implement IsBusy property. Implement ShowBusyIndicator and HideBusyIndicator methods. In ShowBusyIndicator method iterate all open ChildWindows and update their DataContexts.

public class App : Application, INotifyPropertyChanged
{
    public static BusyIndicator GlobalBusyIndicator { get; private set; }

    private bool _isBusy;
    public bool IsBusy
    {
        get
        {
            return _isBusy;
        }
        set
        {
            _isBusy = value;
            RaisePropertyChanged(new PropertyChangedEventArgs("IsBusy"));
        }
    }

    public static void ShowBusyIndicator()
    {
        var popups = VisualTreeHelper.GetOpenPopups();
        foreach (var p in popups)
        {
            ChildWindow cw = p.Child as ChildWindow;
            if (cw != null)
                cw.DataContext = App.Current;
        }
        (Current as App).IsBusy = true;
        GlobalBusyIndicator.IsBusy = true;
    }

    public static void HideBusyIndicator()
    {
        (Current as App).IsBusy = false;
        GlobalBusyIndicator.IsBusy = false;
    }

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        string baseurl = Host.Source.AbsoluteUri;
        BaseUrl = baseurl.Substring(0, baseurl.IndexOf("ClientBin"));

        GlobalBusyIndicator = new BusyIndicator();
        GlobalBusyIndicator.HorizontalAlignment = HorizontalAlignment.Stretch;
        GlobalBusyIndicator.VerticalAlignment = VerticalAlignment.Stretch;
        GlobalBusyIndicator.Content = new Shell();

        this.RootVisual = GlobalBusyIndicator;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void RaisePropertyChanged(PropertyChangedEventArgs e)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) handler(this, e);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!