How to Add Modal Box Like Waiting Cursor on WPF App
Question
In my WPF App, there are certain time consuming actions which are activated when the user clicks a button. What I would like to do is, show the User a Modal Box like Waiting Cursor, much like its done one Web Apps, to indicate that process is going on in the background. What kind of Controls do I have to achieve this?
Solution
Check out the Busy Indicator
OTHER TIPS
You're not looking at much here. I'm not sure how you've designed your application, but for myself, I've created a class NavPage
that extends the UserControl
class and has a property Modal
of type NavPage
and a Close
event.
So basically my NavPage
control allows me to host other NavPag
controls as modals within it. The Close function just closes the Page.
Here's how my template looks for the NavPage
control.
<ControlTemplate x:Key="Fx_NavPage_ControlTemplate" TargetType="{x:Type fx:NavPage}">
<Grid>
<Border x:Name="TheContainer" CornerRadius="{TemplateBinding CornerRadius}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
<ContentControl Content="{TemplateBinding Content}" />
</Border>
<Border x:Name="TheCover" CornerRadius="{TemplateBinding CornerRadius}" Background="#20000000" Visibility="Collapsed" />
<ContentControl x:Name="TheModal" Content="{TemplateBinding Modal}" Visibility="Collapsed" />
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Modal, RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource IsNullConverter}}" Value="False">
<Setter TargetName="TheCover" Property="Visibility" Value="Visible" />
<Setter TargetName="TheModal" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
So basically I just have a Grid
with a ContentControl (TheContainer)
, Border (TheCover)
and another ContentControl (TheModal)
. Then I have a DataTrigger
which checks if the value of the Modal
property on the NavPage
, and if its anything but null, it changes the visibility of TheCover and TheModal to visible. The cover is just a semitransparent Border control that stops the user from clicking controls in the main NavPage.
Hope this helps you out, or you could quite simply just use the BusyIndicator someone suggested above, I've never used it myself so can't give you any input there. If you decide to go this way and need help, let me now I can get more code for you.