In C# WPF, why is my TabControl's SelectionChanged event firing too often?

前端 未结 4 1503
小鲜肉
小鲜肉 2020-11-30 02:41

I have a tabbed GUI with each tab containing a Frame. In one of these Frames there is a DataGrid. When the user selects this tab, I need my datagrid sorted, so I\'m using th

4条回答
  •  时光说笑
    2020-11-30 03:30

    Another good approch is adding a handler to the tabControl.Items.SelectionChanged:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
      ItemCollection view = tabControl.Items;
      view.CurrentChanged += new EventHandler(view_CurrentChanged);
    }
    
    void view_CurrentChanged(object sender, EventArgs e)
    {
      throw new NotImplementedException();
    }
    

    Maybe is not the xamly way, but is less pain as it only fires when an item is changed.

提交回复
热议问题