0

For our application, we need to display the busy indicator during navigation since some controls taking time to load. Normally for long running operation i will create a separate task and will trigger busy indicator in UI Thread but in this case I couldn't do that.

Once the busy indicator started to spin, it got disturbed by Frame.Source or Frame.Navigate which also executes in ui thread. so busy indictor hidden away .

The below is the piece of code i have used for navigation. This is executed as separate task .

public virtual void NavigateTo(string pageKey, object parameter)
        {


                Frame frame = null;
                Action actionToExecuteOnUIContext = () =>
                    {

                        frame = GetDescendantFromName(Application.Current.MainWindow, "ContentFrame") as Frame;
                        if (frame != null)
                        {

                            frame.LoadCompleted -= frame_LoadCompleted;
                            frame.LoadCompleted += frame_LoadCompleted;

                                frame.Source = _pagesByKey[pageKey];
                                frame.DataContext = parameter;



                        }


                    };

                Application.Current.Dispatcher.BeginInvoke(actionToExecuteOnUIContext, DispatcherPriority.Normal);



            }

        }

Any way to fix this or an alternative

WPF & RadBusyIndicator & .Net 4.5

Max_dev
  • 508
  • 7
  • 25

1 Answers1

0

In order to display a busy indicater you have to use a background thread, because the navigation also needs the UI thread.

I suggest to use something like this :

    protected async void Navigation(string pageKey, object parameter)
    {

        await NavigateTo(pageKey,parameter).ContinueWith((t) =>
        {// do UI stuff
            Dispatcher.CurrentDispatcher.InvokeAsync(delegate
            {
                IsBusy = false;
            });

        },
            //sync with UI thread
        TaskScheduler.FromCurrentSynchronizationContext());
    }

    /// <summary>
    /// This method needs to be async to perform async binding
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    private async Task NavigateTo(string pageKey, object parameter)
    {
        //your async method
    }

where IsBusy is the value of the BusyIndicator. You have to set it to true, on navigation started.

Hope this post help you@!

Dragos Stoica
  • 1,753
  • 1
  • 21
  • 42
  • Not helps. My post is different, when you have busy indicator running in UI thread, doing some other action on UI Thread again blocks busy indicator. So how to load the frame without blocking busy indicator – Max_dev Jun 26 '15 at 11:42