-1

I have this code. What I'm trying to make is that when you dial checkbox, the combobox is enabled and if unmarked, it locks.

<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>
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
avechuche
  • 1,470
  • 6
  • 28
  • 45
  • So, can you post your code behind? also, what do you mean by not work? did you come across any error? – User2012384 Oct 09 '15 at 01:42
  • 1
    @User2012384 I don't think OP expects any codebehind for that - something like that should work by itself with just declarative binding ( `IsEnabled = siblingCheckBox.IsChecked`)... Also "current behavior" part is clearly missing from the post. – Alexei Levenkov Oct 09 '15 at 01:44
  • @User2012384 I have no errors, just does not work :( – avechuche Oct 09 '15 at 01:46
  • It would help to add the language your working with and if you would specify what issue your are trying to resolve. Looks like WPF? Also, please clarify what you mean by "dial checkbox"? Your question is unclear. –  Oct 09 '15 at 02:24

1 Answers1

1

I can't post comments yet so I'll post here.

Have you looked at these other posts:

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

How to bind inverse boolean properties in WPF?

EDIT: Try this:

    <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>
Community
  • 1
  • 1
Tyler Jennings
  • 8,761
  • 2
  • 44
  • 39
  • Yeah, that's the solution, add a name to the control. Why not work with FindAnsestor? : S – avechuche Oct 09 '15 at 01:51
  • Not sure about FindAncestor, but just use the name of the checkbox instead. It is more direct. If this works please mark it as answer. Thanks. – Tyler Jennings Oct 09 '15 at 01:53
  • @avechuche does your `CheckBox` actually contain your `ComboBox`? I can see from your XAML that it does not contain your `ComboBox` (just a previous sibling) so `FindAncestor` cannot work. – Hopeless Oct 09 '15 at 02:19