zoukankan      html  css  js  c++  java
  • WPF TreeView SelectedItemChanged called twice

    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(); });
    }
    
  • 相关阅读:
    线段树模板
    树状数组练习
    树状数组模板
    codeforce——思维dp
    fib博弈
    寒假总结
    相邻的数互质
    大数取模运算
    阶乘因式分解(一)
    1和0既非素数也非合数
  • 原文地址:https://www.cnblogs.com/smiler/p/9583294.html
Copyright © 2011-2022 走看看