in wpf datagrid how to get the blank row on top?

前端 未结 4 1725
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 06:32

in wpf datagrid how to get the blank row on top? ie when user wants to add new row, it always comes at the bottom. But I want it to be on top ... can i do this in XAML ?

4条回答
  •  天涯浪人
    2020-12-16 06:47

    This answer depends greatly on how you are binding your DataGrid, specifically what the underlying type of your ItemsSource is. This answer assumes you are using an ObservableCollection. Since you mention WPF specifically, I also assume you mean .NET 4.0, since the DataGrid is only available in Silverlight 3 and .NET 4.0.

    I assume that you are newing up a row by calling

    ItemSource.Add(new MyObject());
    

    To get the behavior you desire, use the following instead:

    ItemSource.Insert(0, new MyObject());
    

提交回复
热议问题