It's quite easy to check if certain container or its children have validation errors. This can be used to disable Save button.
I can use timer
public SomeUserControl()
{
InitializeComponent();
var timer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(100),
IsEnabled = true
};
Loaded += (s, e) => buttonSave.IsEnabled = IsValid(grid);
Unloaded += (s, e) => timer.Stop();
}
to poll and to disable button.
<!-- container with lots of controls, bindings and validations -->
<Grid x:Name="grid">
...
</Grid>
<!-- save button -->
<Button x:Name="buttonSave" ... />
Is there a better way? Ideally I want an event. Unfortunately the only event I've found, Validation.Error event, can only be used on the element with bindings itself. Going through children elements and subscribing (not mentioning what I have to deal with adding new children) feels way worser than polling.
Thoughts?