我有表單的多個datatriggers:從樣式設置器中取消選中複選框?
<Style x:Key="VerifyCheckBox" TargetType="{x:Type CheckBox}">
<Setter Property="Height" Value="14" />
<Setter Property="FontSize" Value="12" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=PrimaryInsuranceCompany, Path=(Validation.HasError)}" Value="True">
<Setter Property="IsEnabled" Value="False" />
<Setter Property="IsChecked" Value="False" />
</DataTrigger>
在複選框的IsEnabled
屬性設置正確。但是,IsChecked
屬性不會取消選中,如果它已被首先手動檢查。
IsChecked
可以從Setter中取消選中嗎?
編輯#1
To complicate matters a bit more, the checkbox is bound to a property in my viewmodel as:
<CheckBox
Style="{StaticResource VerifyCheckBox}"
IsChecked="{Binding PrimaryInsurance.SelectedInsurance.Verify}"
Content="Verify" HorizontalAlignment="Left" Margin="789,92,0,676" Width="46" />
而且有多個DataTrigger S IN的Style.Triggers每個檢查在UI上不同的元件。總之,UI具有所有的數據驗證。例如,上面提到的元素,PrimaryInsuranceCompany是:
<wc:AutoFilteredComboBox
Name="PrimaryInsuranceCompany"
IsEnabled="{Binding PrimaryInsurance.Enabled}"
ItemsSource="{Binding PrimaryInsurance.AllCompanies}"
ItemTemplate="{StaticResource CompanyTemplate}"
IsEditable="True"
IsCaseSensitive="False"
IsTextSearchEnabled="True"
TextSearch.TextPath="Companyname"
Text="{Binding PrimaryInsurance.NewCompanyName, UpdateSourceTrigger=PropertyChanged}"
theFilter="{Binding PrimaryInsurance.TheFilter}"
SelectedItem="{Binding PrimaryInsurance.SelectedInsurance.Company}"
h:ComboBoxRegexValidator.RegexText="{x:Static h:RegexLibrary.NonEmptyRegex}"
HorizontalAlignment="Left" Margin="590,138,0,0" VerticalAlignment="Top" Width="363" />
因此,在特定的組合框元素,我試圖避免重複在視圖模型的驗證過程,因爲它已經直接在視圖中進行。這可以做到嗎?
IsChecked屬性肯定會綁定到某些視圖模型屬性。 – Clemens
@Clemens是的......是的。請看我上面的編輯。 :) –