我在UWP XAML中有一个“妊娠状态”的单选按钮,只有当性别单选按钮被选为“女性”时才应该启用

时间:2018-02-05 08:53:16

标签: .net xaml uwp uwp-xaml

<RadioButton x:Name="radioButton3"  TabIndex="14" GroupName="PregnancyStatus" Content="Yes" IsChecked="{Binding PatientInfo.PregnancyStatus, Converter={StaticResource pregnancyStatusConverter}, ConverterParameter=Yes, Mode=TwoWay}" HorizontalAlignment="Left"  VerticalAlignment="Center"/>
<RadioButton x:Name="radioButton4"  TabIndex="15" GroupName="PregnancyStatus"  Content="No" IsChecked="{Binding PatientInfo.PregnancyStatus, Converter={StaticResource pregnancyStatusConverter}, ConverterParameter=No, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Center" />
<RadioButton x:Name="radioButton5"   TabIndex="16" GroupName="PregnancyStatus" Content="Unknown" IsChecked="{Binding PatientInfo.PregnancyStatus, Converter={StaticResource pregnancyStatusConverter}, ConverterParameter=Unknown, Mode=TwoWay}" HorizontalAlignment="Left"  VerticalAlignment="Center"/>

如果性别单选按钮为“女性”,如何启用此单选按钮,对于“男性”,我应该无法编辑此按钮。

1 个答案:

答案 0 :(得分:0)

您可以使用IsEnabled属性。我们假设您的女性性别单选按钮的x:NameradioFemale。然后,您将添加IsEnabled属性绑定,如下所示:

IsEnabled="{Binding IsChecked, ElementName=radioFemale}"

这意味着一旦选中女性单选按钮,启用属性将为true,反之亦然。所以对于你的代码:

<RadioButton x:Name="radioButton3"  
   IsEnabled="{Binding IsChecked, ElementName=radioFemale}"
   TabIndex="14" GroupName="PregnancyStatus" Content="Yes" 
   IsChecked="{Binding PatientInfo.PregnancyStatus, Converter={StaticResource pregnancyStatusConverter}, ConverterParameter=Yes, Mode=TwoWay}" HorizontalAlignment="Left"  VerticalAlignment="Center"/>
<RadioButton x:Name="radioButton4" 
   IsEnabled="{Binding IsChecked, ElementName=radioFemale}"
   TabIndex="15" GroupName="PregnancyStatus"  Content="No" 
   IsChecked="{Binding PatientInfo.PregnancyStatus, Converter={StaticResource pregnancyStatusConverter}, ConverterParameter=No, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Center" Command="{Binding PregnancyStatusCommand}" />
<RadioButton x:Name="radioButton5" 
   IsEnabled="{Binding IsChecked, ElementName=radioFemale}"
   TabIndex="16" GroupName="PregnancyStatus" Content="Unknown" 
   IsChecked="{Binding PatientInfo.PregnancyStatus, Converter={StaticResource pregnancyStatusConverter}, ConverterParameter=Unknown, Mode=TwoWay}" HorizontalAlignment="Left"  VerticalAlignment="Center"/>