4
按鈕我有這個DataGrid
:禁用/啓用與DataGridTextColumn驗證
<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,按鈕仍然被禁用。