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;
}
}