WPF 制作带TreeView的ComBox
生活随笔
收集整理的这篇文章主要介绍了
WPF 制作带TreeView的ComBox
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1、xaml代码部分
<ComboBox><ComboBoxItem><ComboBoxItem.Template><ControlTemplate><TreeView ItemsSource="{Binding DataContext.ComBoxTreeViewData,ElementName=myWin}"><it:Interaction.Triggers><it:EventTrigger EventName="SelectedItemChanged"><it:InvokeCommandAction Command="{Binding TreeViewNodeSelectedChangedCommand}"/></it:EventTrigger></it:Interaction.Triggers><TreeView.ItemTemplate><HierarchicalDataTemplate ItemsSource="{Binding Children}"><TextBlock Text="{Binding Name}"/></HierarchicalDataTemplate></TreeView.ItemTemplate></TreeView></ControlTemplate></ComboBoxItem.Template></ComboBoxItem></ComboBox>2、创建一个VM以及树对应的model然后进行绑定即可3、创建命令TreeViewNodeSelectedChangedCommand用于将选择的节点的信息显示在ComBox中。
4、为了将信息显示在comBox中可以创建一个textBlock覆盖在ComBox中。即ComBox本身不显示任何值只是作为一个容器使用。
总结
以上是生活随笔为你收集整理的WPF 制作带TreeView的ComBox的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: mysql性能监控 调优_MySQL管理
- 下一篇: .NET Core 人工智能系列-概述