绑定组合框IsEnabled与兄弟CheckBox控件的状态

时间:2015-10-09 01:36:10

标签: c# wpf

我有这个代码。我试图做的是,当你拨打复选框时,组合框被启用,如果没有标记,它会锁定。

<DockPanel Margin="0,0,10,0">
    <CheckBox Margin="5,5,0,5" HorizontalAlignment="Center"
 VerticalAlignment="Center" IsChecked="True" Content="Cliente:" FontSize="15"/>
    <ComboBox Width="150"
      ItemsSource="{Binding Clients}"
      DisplayMemberPath="FullDescription"
      SelectedItem="{Binding SelectedClient}"
      IsEnabled="{Binding IsChecked, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}}"/>
</DockPanel>

1 个答案:

答案 0 :(得分:1)

我还无法发表评论,所以我会在这里发帖。

您是否看过其他帖子:

Disable text box when Check box is Unchecked during run time in C#

How to bind inverse boolean properties in WPF?

编辑: 试试这个:

    <DockPanel Margin="0,0,10,0">
        <CheckBox x:Name="chkEnableBackup" Margin="5,5,0,5" HorizontalAlignment="Center"
 VerticalAlignment="Center" IsChecked="True" Content="Cliente:" FontSize="15"/>
        <ComboBox Width="150"
      ItemsSource="{Binding Clients}"
      DisplayMemberPath="FullDescription"
      SelectedItem="{Binding SelectedClient}"
      IsEnabled="{Binding ElementName=chkEnableBackup, Path=IsChecked}"/>
    </DockPanel>