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;
}
的错误校验码我如何能得到相应的复选框以显示一个错误,如果没有选择至少一个什么建议吗?