Hi,
I know that in WPF, I could bind a button's IsEnabled property with some TextBox to receive the Validation.HasError result as its IsEnabled value. This does work for simple TextBox.
But in my case, I have a DataGrid for user to do the input. And for the TextBox column of the DataGrid, I binding a validation rule to it as followings:
<DataGridTemplateColumn Header=TransformerNumber Width=* HeaderStyle={StaticResource NormalHeader}>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBox Name=txtNumber Style={StaticResource RegularTxtBox}>
<TextBox.Text>
<Binding Path =Number Mode=TwoWay UpdateSourceTrigger=PropertyChanged NotifyOnValidationError=True ValidatesOnDataErrors=True ValidatesOnExceptions=True ValidatesOnNotifyDataErrors=True>
<Binding.ValidationRules>
<local:TransformerNumberValidationRule ValidationStep=UpdatedValue/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
The validation works fine in this case(When the input is incorrect, the TextBox cell is shown with a red border). However, the button I want to disable is totally lost control. Even if the input is incorrect, I can still click the button.
Below is the trigger code for disabling the button
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding={Binding ElementName=txtNumber, Path=(Validation.HasError)} Value=true />
</MultiDataTrigger.Conditions>
<Setter Property=IsEnabled Value=False />
</MultiDataTrigger>
</Style.Triggers>
So, anyone can tell me how could I do this in the situation. Thanks a lot.