How can I cancel a user's WPF TreeView click?

后端 未结 9 1958
长情又很酷
长情又很酷 2020-12-14 03:56

I\'ve got a WPF application with a Treeview control.

When the user clicks a node on the tree, other TextBox, ComboBox, etc. controls on the page are populated with a

9条回答
  •  感动是毒
    2020-12-14 04:28

    You could create your custom control that derives from TreeView and then override the OnSelectedItemChanged method.

    Before calling the base, you could first fire a custom event with a CancelEventArgs parameter. If the parameter.Cancel become true, then don't call the base, but select the old item instead (be careful that the OnSelectedItemChanged will be called again).

    Not the best solution, but at least this keeps the logic inside the tree control, and there is not chance that the selection change event fires more than it's needed. Also, you don't need to care if the user clicked the tree, used the keyboard or maybe the selection changed programatically.

提交回复
热议问题