部分绑定 WPF TreeView
编辑:现在看来这是我正在使用的 Telerik 控件的一个错误。使用 .Net TreeView 重新实现 XAML 后,我得到了预期的结果。我已将此事报告给 Telerik,并将在收到他们的回复后回复此帖子。
我正在尝试(取得了有限的成功)创建一个包含动态和静态数据混合的 TreeView。
您将在下面找到我目前对此的最佳尝试,但是由于我嵌套了 TreeView,因此存在一个副作用,即可能会在选定的父 TreeView 中选择多个项目。当我尝试嵌套 TreeViewItems 时,结果并不乐观,即仅显示 ItemTemplate 中的父级 TreeViewItem 并为其子级创建空间,但没有输出任何内容。
我真的很想知道如何实现我的目标,而不需要在绑定到 TreeView 的集合中指定整个菜单。
谢谢
<telerik:RadTreeView Width="225" HorizontalAlignment="Left" Background="Transparent" FontWeight="SemiBold">
<telerik:RadTreeViewItem Header="Customer" Command="{Binding OpenCustomerCommand}"/>
<telerik:RadTreeViewItem Header="Sites" Command="{Binding OpenSiteBrowserCommand}" ItemsSource="{Binding Sites}">
<telerik:RadTreeViewItem.ItemTemplate>
<DataTemplate>
<telerik:RadTreeView>
<telerik:RadTreeViewItem Header="{Binding Key}"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenSiteCommand}"
CommandParameter="{Binding Value}">
<telerik:RadTreeViewItem Header="Material Profiles"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenMaterialProfileBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Prices"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenPriceBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Orders"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenOrderBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Activity">
<telerik:RadTreeViewItem Header="Collection"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenActivityCollectionsBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Call Outs"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenActivityCallOutBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Gate"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenActivityGateBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="One Off Charges"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenActivityOneOffChargeBrowserCommand}"
CommandParameter="{Binding Value}"/>
</telerik:RadTreeViewItem>
</telerik:RadTreeViewItem>
</telerik:RadTreeView>
</DataTemplate>
</telerik:RadTreeViewItem.ItemTemplate>
</telerik:RadTreeViewItem>
Edit: It now looks like this is a bug with the Telerik controls I'm using. After re-implementing my XAML using the .Net TreeView I get the results I would expect. I've reported this to Telerik and will answer this posting after hearing back from them.
I'm attempting (with limited success) to create a TreeView that contains a mixture of dynamic and static data.
You'll find my current best attempt at this below, however since I'm nesting TreeViews there is a side effect wherein it is possible to have multiple items within the parent TreeView selected. When I've tried nesting TreeViewItems the results were not positive, i.e. only the parent level TreeViewItem in the ItemTemplate is displayed and space for it's children is created but nothing is output.
I would really like to know how to acheive my goal without resorting to specifying the entire menu in collections which I bind to the TreeView.
Thank you
<telerik:RadTreeView Width="225" HorizontalAlignment="Left" Background="Transparent" FontWeight="SemiBold">
<telerik:RadTreeViewItem Header="Customer" Command="{Binding OpenCustomerCommand}"/>
<telerik:RadTreeViewItem Header="Sites" Command="{Binding OpenSiteBrowserCommand}" ItemsSource="{Binding Sites}">
<telerik:RadTreeViewItem.ItemTemplate>
<DataTemplate>
<telerik:RadTreeView>
<telerik:RadTreeViewItem Header="{Binding Key}"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenSiteCommand}"
CommandParameter="{Binding Value}">
<telerik:RadTreeViewItem Header="Material Profiles"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenMaterialProfileBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Prices"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenPriceBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Orders"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenOrderBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Activity">
<telerik:RadTreeViewItem Header="Collection"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenActivityCollectionsBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Call Outs"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenActivityCallOutBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="Gate"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenActivityGateBrowserCommand}"
CommandParameter="{Binding Value}"/>
<telerik:RadTreeViewItem Header="One Off Charges"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=view:WindowViewBase},
Path=DataContext.OpenActivityOneOffChargeBrowserCommand}"
CommandParameter="{Binding Value}"/>
</telerik:RadTreeViewItem>
</telerik:RadTreeViewItem>
</telerik:RadTreeView>
</DataTemplate>
</telerik:RadTreeViewItem.ItemTemplate>
</telerik:RadTreeViewItem>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Telerik 已确认其 RadTreeView 控件无法实现这一点,并且已将其添加到 TODO 列表中。
不管怎样,谢谢你的评论。
Telerik have confirmed that this isn't possible with their RadTreeView control and they've added it to their TODO list.
Thanks for the comments anyway.