ScrollIntoView for WPF DataGrid (MVVM)

前端 未结 4 1154
花落未央
花落未央 2020-12-03 07:44

I\'m using the MVVM pattern, and I\'ve created a binding in XAML for the SelectedItem of a DataGrid. I programatically set the SelectedItem, however when I do so the DataGri

4条回答
  •  一生所求
    2020-12-03 08:03

    The solution of @Edgar works fine, but in my application I had to check the OriginalSource of the SelectionChangedEventArgs as well.

    private void OperatorQualificationsTable_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if ((OperatorQualificationsTable.SelectedItem != null) && (e.OriginalSource?.Equals(OperatorQualificationsTable) ?? false))
        {
            OperatorQualificationsTable.ScrollIntoView(OperatorQualificationsTable.SelectedItem);
        }
    }
    

    My datagrid contains following ComboBoxColumn

    
    

    Everytime when I scrolled up or down the selction changed event was called for the Combobox and it was no longer possible to move the selected item out of the view.

提交回复
热议问题