[WPF系列]-TreeView的常用事项

引言

 

项目经常会用Treeview来组织一些具有层级结构的数据,本节就将项目使用Treeview常见的问题作一个总结。

 

DataBinding数据绑定

 

DataTemplate自定义

<HierarchicalDataTemplate DataType="{x:Type viewModels:FieldViewModel}"
                                              ItemsSource="{Binding SubViewModels}">

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="F:" Style="{StaticResource IconTextStyle}" 
                                Background="LightCoral"/>
                        <TextBlock Text="{Binding CurrentEntity.Value.Name}" Focusable="True">
                            <TextBlock.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="New Well" Command="{Binding AddCommand}"
                                          CommandParameter="{Binding Path=CurrentEntity.Value}" />
                                    <MenuItem Header="Delete" Command="{Binding DeleteCommand}"
                                          CommandParameter="{Binding Path=CurrentEntity.Value}" />
                                </ContextMenu>
                            </TextBlock.ContextMenu>
                        </TextBlock>
                    </StackPanel>
                </HierarchicalDataTemplate>

Style自定义

 

 

 

Events顺序

SelectedItemChanged 发生在TreeView向新selectedItem聚焦(set focus on its new selected item).

一句话: selectedItemChanged –>set foucs on the new selected item.

源自:https://social.msdn.microsoft.com/Forums/en-US/e41ec0e1-f63e-40a3-bfea-1d61d0cfcf1e/set-focus-on-textbox-after-click-on-treeviewselecteditemchanged?forum=wpf&prof=required

[WPF系列]-TreeView的常用事项

上一篇:C#网络编程初步之TCP


下一篇:WPF中实现验证码功能