WPF 制作带TreeView的ComBox
生活随笔
收集整理的這篇文章主要介紹了
WPF 制作带TreeView的ComBox
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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、創(chuàng)建一個(gè)VM以及樹對(duì)應(yīng)的model然后進(jìn)行綁定即可3、創(chuàng)建命令TreeViewNodeSelectedChangedCommand用于將選擇的節(jié)點(diǎn)的信息顯示在ComBox中。
4、為了將信息顯示在comBox中可以創(chuàng)建一個(gè)textBlock覆蓋在ComBox中。即ComBox本身不顯示任何值只是作為一個(gè)容器使用。
總結(jié)
以上是生活随笔為你收集整理的WPF 制作带TreeView的ComBox的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql性能监控 调优_MySQL管理
- 下一篇: cookie的max age