I got a ViewModel which handles Validation using the IDataErrorInfo Interface. This works fine for ComboBoxes, TextBoxes, Checkboxes, etc.
The DatePicker seems to Validate the Input itself based on the Binding to a "DateTime?" property inside the ViewModel which works fine, too.
Now I want to Disable/Enable a Button using Command Binding from inside the ViewModel. If any Control shows a Validation Error, the Button should be disabled.
Using MVVM-Light's RelayCommand I got this working for anyting but the DatePickers , because they validate themselves.
RelayCommand Code:
this.DoSomethingCommand = new RelayCommand(this.DoSomething, this.CanDoSomething);
Is there a way to get their Validation-State into the ViewModel?
I really appreciate some help on this one!
Before anyone mentions it: I already tried using a Multidatatrigger and therefore Handling the Button IsEnabled Property in the View. It didnt work, IsEnabled was the only Property which i couldnt change using datatriggers. Even without any CommandBindings.(maybe because of my companies Authentication-Framework)
Here is the DataTrigger Code i tried:
<Button x:Uid="Button_1"
Content="DoSomething"
IsDefault="True"
Command="{Binding DoSomethingCommand}">
<Button.Style>
<Style x:Uid="Style_1"
TargetType="{x:Type Button}"
BasedOn="{StaticResource {x:Type Button}}">
<Setter x:Uid="Setter_2"
Property="IsEnabled"
Value="false" />
<Style.Triggers>
<MultiDataTrigger x:Uid="MultiDataTrigger_1">
<MultiDataTrigger.Conditions>
<Condition x:Uid="Condition_1"
Binding="{Binding (Validation.HasError), ElementName=ComboBox1}"
Value="false" />
<Condition x:Uid="Condition_2"
Binding="{Binding (Validation.HasError), ElementName=ComboBox2"
Value="false" />
<Condition x:Uid="Condition_3"
Binding="{Binding (Validation.HasError), ElementName=ComboBox3}"
Value="false" />
<Condition x:Uid="Condition_4"
Binding="{Binding (Validation.HasError), ElementName=ComboBox4}"
Value="false" />
<Condition x:Uid="Condition_5"
Binding="{Binding (Validation.HasError), ElementName=ComboBox5}"
Value="false" />
<Condition x:Uid="Condition_6"
Binding="{Binding (Validation.HasError), ElementName=DatePicker1}"
Value="false" />
<Condition x:Uid="Condition_7"
Binding="{Binding (Validation.HasError), ElementName=DatePicker2}"
Value="false" />
</MultiDataTrigger.Conditions>
<Setter x:Uid="Setter_1"
Property="IsEnabled"
Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>