[英]Having trouble with ItemContainerStyle on a Treeview
我在树形视图上设置了以下XML:
<Root Value="YES">
<Child Name="Test">
<Sibling Data="Yes">
<Last UserData="1"/>
</Sibling>
<Sibling Data="No"/>
</Child>
<Child Name="Test2"/>
</Root>
然后在窗口中设置以下代码:
<Window.Resources>
<XmlDataProvider x:Key="dataProvider" XPath="Root" Source="C:\XML.xml" />
<HierarchicalDataTemplate DataType="Root" ItemsSource="{Binding XPath=*}">
<TextBlock Text="{Binding XPath=@Value}" />
<HierarchicalDataTemplate.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="Blue">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</HierarchicalDataTemplate.ItemContainerStyle>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="Child" ItemsSource="{Binding XPath=*}">
<TextBlock Text="{Binding XPath=@Name}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="Sibling" ItemsSource="{Binding XPath=*}">
<TextBlock Text="{Binding XPath=@Data}" />
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<TreeView Margin="12" x:Name="trv"
ItemsSource="{Binding Source={StaticResource dataProvider}}" />
</Grid>
我希望有一个边界控件围绕每个节点的所有子项,如下图所示:
http://www.hardcodet.net/uploads/2008/03/tree-dialogik.png
换句话说,在链接到的图像中,您会注意到父节点dialogik。内存周围有一个深灰色边框,周围是它的子级。 那就是我想要达到的效果。
我需要在代码中进行哪些更改才能使其正常工作?
谢谢 !!
使用TreeView是不可能的。 您可以使用扩展器,请参见此处:
http://msdn.microsoft.com/zh-CN/library/system.windows.controls.expander.aspx
..然后类似地绑定它:您将有一个ItemsControl,它为每个项目输出一个Expander,然后Expander将递归地包含另一个用于子项的ItemsControl。
希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.