2

I want to show a loading dialog while opening a View/UserControl that takes a while to open. I know I can use Loaded event to close the dialog once the UI is laid out and shown. I am doing this like in the sample code that is shown below.

My question is: Is there any event that I can use in a similar manner to open the dialog when the layout/loading process starts?

I could open the loading dialog from the ViewModel that opens this View/UserControl, but this would spread out the logic. Furthermore, since I am using messaging (from MvvmLight) to signal the View/UserControl to load it this would result in an unclean solution IMO. So any ideas how to achieve this?

View:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
        <i:InvokeCommandAction Command="{Binding ViewLoadedEventHandlerCommand}" />
    </i:EventTrigger>
</i:Interaction.Triggers>

ViewModel:

    private ICommand viewLoadedEventHandlerCommand;
    public ICommand ViewLoadedEventHandlerCommand
    {
        get
        {
            if (viewLoadedEventHandlerCommand == null)
                viewLoadedEventHandlerCommand = new RelayCommand(() => Debug.WriteLine("MainView was loaded."));
            return viewLoadedEventHandlerCommand;
        }
    }
Florian Schaal
  • 2,586
  • 3
  • 39
  • 59
packoman
  • 1,230
  • 1
  • 16
  • 36
  • Simplest is to use an overlay control on the application UI that is shown when you're loading on a background thread. There are lots of controls and examples of how to use them around. Overlay http://stackoverflow.com/questions/5450985/how-to-make-overlay-control-above-all-other-controls Showing/hiding while loading data http://stackoverflow.com/questions/8710486/busy-effect-overlay overlay UI http://stackoverflow.com/questions/6359848/wpf-loading-spinner etc etc –  Jul 11 '16 at 15:09

0 Answers0