我可以使用复选框和单选按钮来控制文本框的启用/禁用吗?
我的用户界面是这样的,复选框控制单个文本框状态,而单选按钮控制文本框和复选框的启用/禁用状态。
答案 0 :(得分:3)
您可以使用多重绑定在UI中执行此操作。这看起来像这样:
<TextBlock>
<TextBlock.IsEnabled>
<MultiBinding Converter="{StaticResource MultiConverter}">
<Binding ElementName="MyCheckBox" Path="IsChecked" />
<Binding ElementName="MyRadioButton" Path="IsChecked" />
</MultiBinding>
</TextBlock.IsEnabled>
</TextBlock>
<CheckBox x:Name="MyCheckBox"/>
<RadioButton x:Name="MyRadioButton"/>
转换器查看收音机的已检查状态和复选框
public class MultiConverter: IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
bool isCheckBoxChecked = (bool)value[0];
bool isRadioButtonChecked = (bool)value[1];
return isCheckBoxChecked && isRadioButtonChecked;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}