2014-07-03 59 views
0

以下作品是树形在不工作

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

中的树型视图样式的绑定IsExpanded到templatedParent这并不因为它是在不同的资源为树型视图风格

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

请让我知道哪里出了问题

回答

0

Th这错误似乎是蜜蜂,你错过了一些东西。 TemplatedParent是指模板正在应用到的Control实例,而不是其DataContext。检查this Question。一个简单的解决方案应该使结合到其DataContext

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

希望帮助...