简体   繁体   中英

How to trigger the Selected event when I select one item everytime

I have a TreeView like this:

xaml:

<TreeView>
     <TreeViewItem Header="header" Name="mytreeViewItem" Selected="mytreeViewItem_Selected"/>
</TreeView>

xaml.cs:

mytreeViewItem.ItemsSource = new List<string>(){"a"};

When I select the TreeViewItem nameed a , it will trigger event mytreeViewItem_Selected . But when I select the TreeViewItem again, it wont trigger the event again. How can I trigger the Selected event when I select the TreeView every time?

您可以根据需要使用PreviewMouseDown事件或类似的事件(例如PreviewMouseLeftButtonDown )。

Can you have

item.IsSelected = false;

in your event handler? So when you click again, the Selected event re-fires. I don't think it will fire if the same is still selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM