Dim Windows and Show Waiting Animation

Topics: Prism v2 - WPF 3.5
Jun 22, 2009 at 9:30 PM

When I load data into my app, I want to dim the window and show a waiting animation just like the Lightbox 2 script works.  How would I go about doing this?  Thanks.

Jun 23, 2009 at 5:33 PM

As a follow-up, I added the following to my Shell.xaml file:

            <StackPanel Width="Auto" Height="Auto" Margin="10,10,10,10">
                    <ItemsControl cal:RegionManager.RegionName="{x:Static infrastructure:RegionNames.MainRegion}" Width="Auto" Height="Auto" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"/>
                    <Border x:Name="panelLoading" Visibility="Collapsed" >
                            <Border Background="Black" Opacity="0.49"></Border>
                            <Viewbox Width="100" HorizontalAlignment="Center">
                                <Frame Source="ucWaiting.xaml" />
However I'm not sure how to wire up events etc. in the ShellPresenter to change the visibility of panelLoading.

Jun 23, 2009 at 6:19 PM

I moved the Border to my actual view and out of the shell.  I had a method to my view's interface to toggling the visibility of the Border. 

The problem I now have is that when my presenter calls into the view, and the view changes the visibility, I do not see a change in my app. 

Is this a UI thread issue?

Jun 23, 2009 at 6:42 PM

I thought it might be a threading issue, so I'm doing this in my view:

        private delegate void ShowWaitScreenInvoker(bool show);

        public void ShowWaitScreen(bool show) {
            var invoker = new ShowWaitScreenInvoker(ShowWaitScreenCallback);
            Dispatcher.Invoke(DispatcherPriority.Normal, invoker, show);

        private void ShowWaitScreenCallback(bool show) {
            borderLoading.Visibility = show ? Visibility.Visible : Visibility.Collapsed;
However I'm still now seeing the change occur.


Jun 23, 2009 at 9:11 PM

Hi bittondb,


If I understood your scenario correctly you want to dim a window while certain process occurs.  You have already achieved the visual effect, but you can't communicate between the dimmed view and the shell window.


The view that implements the dim beheaviour and the Shell should be decoupled. So the approach that Prism-v2 enables to communicate between them is using the EventAggregator.

If your case, when the process starts you should publish an event from the shell (or the module that starts the process) and subscribe to this event in the view and dim  the window. When the process ends, you can publish another event and show the window normally again.


You can read further about communication in prism applications in the following article from the documentation:

·         Communication


Regarding your question about the UI Thread, you will see that the EventAggregator.Subscribe method provides an overload to specify on which thread the callback delegate will be invoked.


On the other hand, to show the Waiting Animation you might  find useful the ProgressBar Control as it can be easily customizable.


Hope it helps!


Matias Bonaventura


Jun 23, 2009 at 9:46 PM

Would I publish and subscribe to these events within my same view module?

Jun 23, 2009 at 10:16 PM

In my view presenter, i publish and also subscribe to the same event.  I use ThreadUI as the thread option, and I also see my callback being hit however still no change.

If I comment out the stuff I do after displaying the wait screen (as well as the call to remove it), it works after the method returns.  Something is blocking. 

I even added a Thread.Sleep(5000) to add artificial delay and still no-go.

Jun 24, 2009 at 4:46 PM

Once I made my database call truely async (with callback), then the events worked as expected.