TreeView with HierarchicalDataTemplate, Is there a way to access the TreeViewItem events like MouseDoubleClick and ItemSelected?

StackOverflow https://stackoverflow.com/questions/5985082

  •  12-11-2019
  •  | 
  •  

문제

I made a TreeView with HierarchicalDataTemplate. Is there a way to access the TreeViewItem events like MouseDoubleClick() and ItemSelected().

Here is my code:

<HierarchicalDataTemplate DataType="{x:Type local:Artist}" ItemsSource="{Binding Albums}">
    <TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
도움이 되었습니까?

해결책

What you want to do is set an ItemContainerStyle and then use EventSetters

<TreeView.ItemContainerStyle>
    <Style TargetType="{x:Type TreeViewItem}">
        <EventSetter Event="TreeViewItem.MouseDoubleClick"
                     Handler="TreeViewItem_MouseDoubleClick"/>
        <EventSetter Event="TreeViewItem.Selected"
                     Handler="TreeViewItem_Selected" />

....
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top