WPF 双击 TreeviewItem 子节点
我在树视图中有一个树视图项目,该项目将有一个绑定到它的列表:
<TreeViewItem Name="tviOffline" Foreground="Red" FontWeight="Bold"
Header="Offline">
<TreeViewItem.ItemTemplate>
<DataTemplate DataType="{x:Type local:Buddy}">
<StackPanel>
<TextBlock Text="{Binding Nick}" FontSize="10" Foreground="#8CFFD528" />
</StackPanel>
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
我无法弄清楚如何让它的每个子项都有双击事件。
任何帮助表示赞赏。非常感谢。
I have a treeview Item as such in a treeview that will have a list bound to it:
<TreeViewItem Name="tviOffline" Foreground="Red" FontWeight="Bold"
Header="Offline">
<TreeViewItem.ItemTemplate>
<DataTemplate DataType="{x:Type local:Buddy}">
<StackPanel>
<TextBlock Text="{Binding Nick}" FontSize="10" Foreground="#8CFFD528" />
</StackPanel>
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
I cannot figure out how to get each of its childs to have a double click event.
any help is appreciated. thanks much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
然后,必须按如下方式编写处理程序,以防止在连续的父 TreeViewItems 上触发双击:
感谢 Aurelien Ribon 完成了 90% 的工作。双击问题在 Stack Exchange 上的其他帖子中似乎是众所周知的。只需将两种解决方案合并为一个答案即可。
And THEN, the handler has to be written as follows in order to prevent the double-click from firing on successive parent TreeViewItems:
Thanks to Aurelien Ribon for getting 90% of the way there. The double-click problem seems to be well-known in other postings on Stack Exchange. Just consolidating both solutions into one answer.
这是我设法让它适用于所有情况的唯一方法:
This is the only way I managed to get it to work for all the cases: