2
我有三個複選框有自己的錯誤檢查,以確定它們是否被檢查是有效的,但我還想強制執行,在繼續之前至少必須檢查一個複選框。我目前正在使用IDataErrorInfo進行單獨的錯誤檢查,並試圖使用BindingGroups來檢查至少有一個檢查沒有成功。強制一個或多個複選框被選中
這裏的XAML,
<StackPanel Orientation="Horizontal" Margin="5,2">
<Label Content="Checkboxes:" Width="100" HorizontalContentAlignment="Right"/>
<CheckBox Content="One" Margin="0,5">
<CheckBox.IsChecked>
<Binding Path="One" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<DataErrorValidationRule />
</Binding.ValidationRules>
</Binding>
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="Two" Margin="5,5">
<CheckBox.IsChecked>
<Binding Path="Two" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<DataErrorValidationRule />
</Binding.ValidationRules>
</Binding>
</CheckBox.IsChecked>
</CheckBox>
<CheckBox Content="Three" Margin="0,5">
<CheckBox.IsChecked>
<Binding Path="Tree" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<DataErrorValidationRule />
</Binding.ValidationRules>
</Binding>
</CheckBox.IsChecked>
</CheckBox>
</StackPanel>
背後
public string this[string property]
{
get {
string result = null;
switch (property) {
case "One":
{
if (One) {
if (CheckValid(One)) {
result = "Invalid Entry";
}
}
}
break;
case "Two":
{
if (Two) {
if (CheckValid(Two)) {
result = "Invalid entry";
}
}
}
break;
case "Three":
{
if (Three) {
if (CheckValid(Three)) {
result = "Invalid entry"
}
}
}
break;
}
return result;
}
的錯誤校驗碼我如何能得到相應的複選框以顯示一個錯誤,如果沒有選擇至少一個什麼建議嗎?