Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 绑定组合框已启用到同级复选框控件';s州_C#_Wpf - Fatal编程技术网

C# 绑定组合框已启用到同级复选框控件';s州

C# 绑定组合框已启用到同级复选框控件';s州,c#,wpf,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

我有这个密码。我想说的是,当你拨复选框时,组合框是启用的,如果没有标记,它会锁定

<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>

我还不能发表评论,所以我会在这里发表

你看过这些其他帖子了吗:

编辑: 试试这个:

    <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>


那么,你能把你的代码放在后面吗?还有,你说不工作是什么意思?您遇到任何错误了吗?@User2012384我认为OP不需要任何代码隐藏-类似的东西应该只通过声明性绑定(IsEnabled=siblingCheckBox.IsChecked)就可以自己工作。。。此外,文章中明显缺少“当前行为”部分。@User2012384我没有错误,只是不起作用:(这将有助于添加您使用的语言,以及您是否指定您试图解决的问题。看起来像WPF?另外,请澄清“拨号复选框”是什么意思)?您的问题不清楚。是的,这就是解决方案,在控件中添加一个名称。为什么不使用FindAncestor?:不确定FindAncestor,但只使用复选框的名称。它更直接。如果有效,请将其标记为答案。谢谢。@avechuche您的
复选框是否实际包含您的
组合框
?我可以从您的XAML中看出,它不包含您的
组合框
(只是以前的兄弟姐妹),因此
FindAncestor
无法工作。