0

the following works which is within treeview

<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" 
      Value="{Binding Path=IsExpanded, Mode=TwoWay}" />

this doesnt as it is in the different resource as treeviewItem style

<ToggleButton x:Name="Expander" Style="{StaticResource TreeViewExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"/>

Please let me know where am going wrong

Vijay
  • 1

1 Answers1

0

The wrong this seems to bee that you are missing something. The TemplatedParent is refers to the Control instance that the template is being applied to, and not to its DataContext. Check this Question. A simple solution should be make the binding to its DataContext:

IsChecked="{Binding DataContext.IsExpanded, RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"

Hope helps...

Community
  • 1
  • 1
Raúl Otaño
  • 4,640
  • 3
  • 31
  • 65