WPF Listview SelectionChanged event

前端 未结 5 1535
滥情空心
滥情空心 2021-02-05 17:04

I have a ListView binding to an ItemsSource and the SelectionChanged event is firing on the load/databound events? I assume that it is bec

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 17:21

    you can use window loaded event to block the action

    bool loaded = false;
    
    window.Loaded += new RoutedEventHandler(MainWindow_Loaded);
    
    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
       windowLoaded = true;
    }
    
    private void ActiveCasesView_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
    {
    
    if(!loaded)
    return ;
    
    //do actions here ....
    
    }
    

提交回复
热议问题