MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
14.82k stars 3.4k forks source link

ToggleButton throws Exception with error on ValidatesOnDataErrors/IDataErrorInfo #3585

Closed Drexel2k closed 2 weeks ago

Drexel2k commented 3 weeks ago

Bug explanation

Hello,

I validate user inputs in an MVVM app with MaterialDesignInXamlToolkitwith with IDataErrorInfo implementation on the ViewModel and ValidatesOnDataErrors=True on the controls's binding.

It works fine on all controls but ToggleButotn, if the validation returns an error, I receive System.InvalidOperationException: ''{DependencyProperty.UnsetValue}' is not a valid value for property 'ErrorTemplate'.'

Here is a minmal example: https://github.com/Drexel2k/Material_MVVM_Toggle_IDataErrorInfo. As long as the 'Validate with error' box is not checked, you can change the toggle and the text and 'public string this[string columnName]' returns an empty string, which means the value of the control is valid.

If you check 'Validate with error' box 'public string this[string columnName]' returns a string with content, indicating an error, for the text box it is fine, the ToggleButton throw an exception.

Here is also an example with pure WPF, all variants work fine here: https://github.com/Drexel2k/Wpf_MVVM_Toggle_IDataErrorInfo

Version

5.0.0