WPF嵌套扩展器绑定到ListBoxItem不起作用
问题描述:
我试图使用Expander
与一次打开时间为。我从MSDN Forum Link得到了一个代码。WPF嵌套扩展器绑定到ListBoxItem不起作用
<ListBox>
<!-- all styles and templates-->
<Expander Header="One"><!-- some content --></Expander>
<Expander Header="Two"><!-- some other content --></Expander>
</ListBox>
这是工作的罚款。 上述扩展器中只有一个将在时间开放。
但是,如果我尝试一个嵌套的扩展器,较低的扩展器不按要求打开和关闭作为上述代码。这意味着如果我添加内容扩展“两个”像下面
<Expander Header="Two">
<ListBox>
<!-- same styles and templates as above-->
<Expander Header="Sub-One"><!-- some content --></Expander>
<Expander Header="Sub-Two"><!-- some other content --></Expander>
</ListBox>
</Expander>
扩展器“亚一”和“分二”是一些如何链接到同一ListBoxItem
到扩展“二”是附
我想我需要做出一些变化的结合,但不能这样做。
<Style TargetType="{x:Type Expander}">
<Setter Property="IsExpanded"
Value="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
</Style>
任何指导都会有很大的帮助。
注: - 很少有东西,我试过
-
- 在代码中扩展的经过家长,只有列表框快到了,有一个在层次结构没有ListBoxItem的
- 尝试添加不同的值AncestorLevel,无除1值工作
- 正想着,绑定到列表框的SelectedIndex的,这也是我不能让它工作作为无法想转换的SelectedIndex到IsExpandable的,即使我使用转换器