Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Hierachial datatemplate within a Treeview as follows.

<TreeView Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Path=CatogoryList}" MaxHeight="200">
   <TreeView.ItemTemplate>
      <HierarchicalDataTemplate ItemsSource="{Binding Path=DataItemCollection}">
         <CheckBox Content="{Binding Path=Caption}"/>         <HierarchicalDataTemplate.ItemTemplate>
            <DataTemplate>
               <Grid IsEnabled="{Binding Path=IsChecked, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=CheckBox}}">
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition SharedSizeGroup="Captions" Width="Auto"/>
                     <ColumnDefinition SharedSizeGroup="Colours" Width="70"/>
                  </Grid.ColumnDefinitions>
                  <CheckBox Grid.Column="0" Content="{Binding Path=Caption}" VerticalAlignment="Center"/>
                  <ig:XamColorPicker Grid.Column="1" SelectedColor="{Binding Path=Color}"/>
               </Grid>
             </DataTemplate>
          </HierarchicalDataTemplate.ItemTemplate>
       </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>


I am attempting to bind the IsEnabled of the child grid element to the checked value of the parent items template (the elements in bold).

This is not working, WpfSnoop suggests that the hireachal structure of the controls is as follows

TreeViewItem
   Grid
      Expander
          Selection_Border
             Grid
                Part_Header
                   CheckBox           <---The target Checkbox
                ItemsHost
                   StackPanel
                      TreeViewItem
                         Grid
                            Selection_Border
                               Grid   <--- The grid I wish to bind from


I can see that with RelativeSource I can walk back up the tree to a parent control, but due to the way the TreeViewItem is constructed, the CheckBox is on a seperate hierachial path.

Is there anyway I can bind to this directly?

Many thanks

Paul
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900