Reputation: 4002
I have a Window, that has fields that let the user fill in with values, but when I show a MessageBox to tell the user that some of the fields are invalid, it prevents the user from changing from the MessageBox to the Window.
How would I create the MessageBox so that it allows the Window to be accessible while having the MessageBox? Should I multi-thread it? Is there a way to make an object like MessageBox that doesn't lock up the rest of the application?
Code:
string unfilled = @"The following fields are mandatory and are required to continue:";
bool invalid = false;
foreach(Field f in _view.FormFields) {
if(f.IsMandatory > 0 && !f.IsValid) {
unfilled += "\n" + f.LongDisplay;
foreach(string s in f.ErrorMessages) {
unfilled += "\n\t" + s;
}
invalid = true;
}
}
if(invalid) {
MessageBox.Show(unfilled, "Invalid Submission"); <-- locks up WPF application
return;
}
Upvotes: 2
Views: 368
Reputation: 387
You could define a separate Grid at the bottom of the markup and display the grid with the message to your users by setting the visibility to visible . Then trap the mouse click of the window and if the grid that you display the messages in is visible set the visibility to hidden. Below is an example of the popup grid.
<Grid x:Name="MyMessageBox" Visibility="Hidden">
<Grid Background="Black" Opacity="0.5"/>
<Border
MinWidth="250"
Background="Orange"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="0,55,0,55"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<StackPanel>
<TextBlock Margin="5" Text="" Name="MessageText" FontWeight="Bold" FontFamily="Cambria" />
</StackPanel>
</StackPanel>
</Border>
</Grid>
Upvotes: 0
Reputation: 4319
It sounds like you may be better displaying text on the wpf form in this case. I'm not sure a UI with a floating validation messagebox would be very intuitive.
Even better would be to look at the validation stuff that wpf supports out of the box to highlight the required items where they need to be entered.
Upvotes: 0
Reputation: 16705
The MessageBox is modal to the form it's shown from.
As a workaround, you could always display a separate wpf form. Alternatively, you could display the error text on the form you're currently on.
Upvotes: 4