我有这个DataGrid
:
<DataGrid ItemsSource="{Binding CustomerXml}"
Name="customersDataGrid" AutoGenerateColumns="False" DataContext="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Header="Name">
<DataGridTextColumn.Binding>
<Binding Path="Name" ValidatesOnDataErrors="True"
UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
<Binding.ValidationRules>
<local:NameValidationRule/>
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
...
</DataGrid.Columns>
</DataGrid>
我正在尝试按ValidationRule
结果禁用和启用保存按钮。
<Button Content="Save" Name="save" Click="save_Click">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="IsEnabled" Value="false" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition
Binding="{Binding ElementName=customersDataGrid,
Path=(Validation.HasError)}" Value="false" />
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="true" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
但如果ValidationResult
设置为 true 或 false,按钮仍处于禁用状态。