当前位置: 移动技术网 > IT编程>开发语言>.net > WPF TreeView SelectedItemChanged called twice

WPF TreeView SelectedItemChanged called twice

2018年09月05日  | 移动技术网IT编程  | 我要评论

朱雀橙,反恐精英为什么进不去,鱼鹰

how to avoid wpf treeview selecteditemchanged being called twice
very often, we need to execute some code in selecteditemchanged depending on the selected treeviewitem. but selecteditemchanged is called twice. this is due to stealing focus from the main window, which is screwing something up.

what we have to do to avoid this is simply delay the call to our code, i.e., myfunction() which we need to execute in selecteditemchanged. here's a workaround which delays the call to open the new window until the item selection code finishes up:

private delegate void noargdelegate();

void window1_selecteditemchanged(object sender, routedpropertychangedeventargs<object> e)
{
  dispatcher.begininvoke(dispatcherpriority.background, 
        (noargdelegate)delegate { myfunction(); });
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网