DataGrid 使用模型列后实现点击列名称排序
代码如下:
1 <DataGridTemplateColumn Header="型 号" SortMemberPath="OrderID.Description" CanUserSort="True" > 2 <DataGridTemplateColumn.CellTemplate> 3 <DataTemplate> 4 <TextBox IsReadOnly="True" Text="{Binding OrderID.Description}" BorderThickness="0,0,0,0"></TextBox> 5 </DataTemplate> 6 </DataGridTemplateColumn.CellTemplate> 7 </DataGridTemplateColumn> 8 <DataGridTemplateColumn Header="序列号" SortMemberPath="SN" CanUserSort="True" > 9 <DataGridTemplateColumn.CellTemplate> 10 <DataTemplate> 11 <TextBox IsReadOnly="True" Text="{Binding SN}" BorderThickness="0,0,0,0"></TextBox> 12 </DataTemplate> 13 </DataGridTemplateColumn.CellTemplate> 14 </DataGridTemplateColumn>
实现字段 : SortMemberPath="OrderID.Description" CanUserSort="True"