开发者

How to set SortDirection of a WPF datagrid as Ascending on datagrid initialization

开发者 https://www.devze.com 2023-04-03 19:54 出处:网络
I have a simple datagrid which can be sorted by开发者_如何学JAVA clicking the column header. When I open the window, datagrid is not sorted. Then, when I click, arrow appears and it\'s sorted asc, cli

I have a simple datagrid which can be sorted by开发者_如何学JAVA clicking the column header. When I open the window, datagrid is not sorted. Then, when I click, arrow appears and it's sorted asc, click again - sorted desc etc. very simple.

What I need to do, is to open window with already sorted datagrid. So arrows (that shows which direction datagrid is sorted) should be always visible. I have to have my datagrid sorted all the time. How can I do that? I prefer to do that in xaml, but any solution will be great.

BTW. App in .NET4


You can set your sort on the column itself

<DataGrid>
    <DataGrid.Columns>
        <DataGridTextColumn SortMemberPath="Name" SortDirection="Descending" />
    </DataGrid.Columns>
</DataGrid>


it depends on the design of your grid, you can do this in XAML directly, for example having an entry like this:

<Trigger Property="SortDirection" Value="Ascending">

check this page:

Styling Microsoft’s WPF datagrid


DataGridColumn.SortDirection. This property gets or sets direction of the sorting.

0

精彩评论

暂无评论...
验证码 换一张
取 消