Reputation: 9407
My application takes almost 4 seconds to completely shut down after the user confirms the shutting down. I am trying to show some activity and maybe a progress to the user within those 3 seconds. So the scenario would be something similar to
ButtonClose_Click() -> Are you sure you want to exit? -> Yes -> "Closing"
I tried to just display a window (messagebox) but I am using DevExpress windows and they are either OkCancel
, Ok
, YesNo
and YesNoCancel
so basically it needs a user input to continue:
Application.Current.Dispatcher.Invoke(
() =>
{
DXMessageBox.Show(Application.Current.MainWindow,
"Text Here..", "Title Here.. ", MessageBoxButton.OKCancel, MessageBoxImage.Information); // Ok by Default
});
This is what I have:
var result = DXMessageBox.Show(Application.Current.MainWindow,
"Are you sure you want to EXIT the application?",
"Attention", MessageBoxButton.OKCancel, MessageBoxImage.);
if (result == MessageBoxResult.OK)
{
//
// I want to show or display some "loading" activity here till the below code finishes executing"
//
mainViewModel.SaveDatabase(); // save database+
mainViewModel.CaptureViewModel.cameraController.TurnCameraLights(false, false, false); // turn off some lights
mainViewModel.CaptureViewModel.Uninitialize(); // clear stuff
Environment.Exit(0);
}
How could I approach that?
Upvotes: 0
Views: 89
Reputation: 7183
I use the ProgressRing from MahApps.Metro.
http://mahapps.com/controls/progress-ring.html
The code is open source or you can get the binaries using Nuget.
Upvotes: 1
Reputation: 91
Here is a simple busy indicator that I've used a few times. You just need a property IsBusy in your viewmodel. Just place this over the top of the rest of your controls.
The best thing is that it won't show over your controls while you're editing in the design view!
<Grid>
<!--all of your controls-->
<!--Loading Indicator-->
<Border x:Name="_LoadingIndicator" Background="#AA000000">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Red" FontSize="80">Loading...</TextBlock>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsBusy}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
</Grid>
Here is what it will look like:
Upvotes: 1
Reputation: 137148
You could use the WPF Toolkit Busy Indicator:
https://wpftoolkit.codeplex.com/wikipage?title=BusyIndicator&referringTitle=Home
You wrap your control with the indicator then set the bound flag to True for the duration of the long running process.
Upvotes: 1