Displaying Broken Rules and Warnings in WPF

There are two ways you can display your broken rules and warnings in a WPF application, controlled by two window-level properties: DisplayErrorProvider and DisplayErrorDialog.

Displaying Broken Rules and Warnings

The default method for displaying broken rules and warnings is by means of both an error dialog and the MM .NET Error Provider. When a window's DisplayErrorDialog property is true, if the user encounters broken rules when saving data at run time, they will first see the following dialog:

When the user clicks OK, the MM .NET Error Provider displays a red border around user interface element associated with a broken rule:

If the user corrects the problem and saves the data, the red borders automatically disappear. They also disappear if the user cancels pending changes.

If the user encounters a warning when saving data at run time, they will first see the following dialog:

When the user clicks OK, the MM .NET Error Provider saves the data, since it is only a warning, not a broken rule.

If the user encounters both broken rules and warnings, they will see a dialog that lists both:


Note: If you want to change the appearance of this dialog, see the section below Changing How Broken Rules and Warnings are Displayed.

Turning Off the Display of Broken Rules and Warnings

If you want to turn off the display of error provider red borders, set the window's DisplayErrorProvider property to false (it's true by default).

If you want to turn off the display of the error dialog, set the window's DisplayErrorDialog property to false (it's true by default).

Displaying Broken Rules When Leaving a User Interface Element

If you prefer to display broken rules as soon as a user leaves a particular user interface element, the businiess rule methods are designed in such a way that they can be called directly from the user interface.

For example, in C#:

private void txtCustomerID_LostFocus(object sender, RoutedEventArgs e)
{
    this.Order.Rules.ClearAll();
    if (this.Order.Rules.ValidateCustomerID(this.txtCustomerID.Text) != null)
    {
        mmAppWPF.MessageBox.Show(this.Order.Rules.GetAllBrokenRules(),
            "Data Entry Error",
            MessageBoxButton.OK, MessageBoxImage.Warning);
    }
}

Changing How Broken Rules and Warnings are Displayed

Whether you are displaying broken rules and warnings in a simple dialog or you are using the MM.NET Error Provider, you can easily change the way these error messages are displayed to the user.

Broken Rules and Warnings in a Simple Dialog

If you are using a simple dialog to display your broken rules and warnings, you can change how they are displayed by overriding the DisplayBrokenRules() method in your window.

This method receives the business rule object as a parameter. You can create your own custom broken rules window or change the existing BrokenRulesWindow.xaml that is automatically added to your project. If you create a completely new error dialog then you can instantiate and call it from the DisplayBrokenRuleDialog method.

For example, in C#:

protected virtual void DisplayBrokenRuleDialog (mmBusinessRule businessRules)
{
	MyBrokenRulesWindow window = new MyBrokenRulesWindow(businessRules);
	window.Show();
}

And in VB .NET:

Protected Overridable  Sub DisplayBrokenRuleDialog (ByVal businessRules As mmBusinessRule)
	Dim window As MyBrokenRulesWindow =  New MyBrokenRulesWindow(bizbusinessRules) 
	window.Show()
End Sub


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/26/18
Comment or report problem with topic