ScrollIntoView for WPF DataGrid (MVVM)

前端 未结 4 1158
花落未央
花落未央 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条回答
  •  萌比男神i
    2020-12-03 08:00

    I am new to MVVM. I understand the idea of MVVM and try to implement everything correctly. I had a similar problem to above and I ended up with 1 line in XAML and 1 line in code behind. The rest of the code is in the VM. I did the following in XAML

    
    

    And this in the code behind:

    private void Selection1List_SelectionChanged(object sender, SelectionChangedEventArgs e) {
        Selection1List.ScrollIntoView(Selection1List.SelectedItem);
    }
    

    and this works fine.

    I know some people don't want even one line of code in the code behind the window. But I think this 1 line is just for the view. It has nothing to do with the data or with the logic of the data. So I would think this is no violation of the MVVM principle - and so much easier to implement.

    Any comments are welcome.

提交回复
热议问题