Closed amkuchta closed 10 years ago
You'll need to set the 'SortMemberPath' property on any CellTemplateColumn you want sorting. For example, <DataGridTemplateColumn Header="Status" SortMemberPath="Status" ...
@jimbobsmith, this allows me to sort the DataGrid one time, but subsequent clicks on the other headers to not cause re-sorting. Any ideas?
You'll need to set that property on each Template column you want sorting on.
I did that: new XAML:
<DataGrid x:Name="dgFiles"
Grid.Column="2"
Grid.ColumnSpan="3"
Margin="10,0,0,0"
Grid.RowSpan="8"
Grid.Row="1"
Height="403"
VerticalAlignment="Top"
BorderThickness="1"
ScrollViewer.VerticalScrollBarVisibility="Auto"
AllowDrop="True"
CanUserReorderColumns="True"
CanUserResizeColumns="True"
CanUserSortColumns="True"
AutoGenerateColumns="False"
ItemsSource="{Binding FileList}"
IsEnabled="{Binding IsEnabled}"
SelectionUnit="FullRow"
BorderBrush="#FFCCCCCC"
HorizontalGridLinesBrush="#FFCCCCCC"
GridLinesVisibility="Horizontal">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Filename"
Width="5*"
SortMemberPath="Filename">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FileName}"
TextTrimming="CharacterEllipsis"
ToolTip="{Binding FileName}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="File Type"
Width="2.5*"
SortMemberPath="File Type">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FileType}"
TextTrimming="CharacterEllipsis"
ToolTip="{Binding FileType}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Status"
Width="2.5*"
SortMemberPath="Status">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Status}"
TextTrimming="CharacterEllipsis"
ToolTip="{Binding Status}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Its typos in this case: 1) 'Filename' should be 'FileName' (capital N) to match the property name) 2) 'File Type' should be 'FileType' (no space) to match the property name
:)
Worked like a charm, thanks!
np
I am using MA.M version 0.13.0.116-ALPHA, and am unable to sort any column other than a CheckboxColumn on any of my three DataGrids (one of which does not even have a CheckboxColumn. Below is the XAML for one of the DataGrids:
DataGrid XAML
I think that the issue was introduced with this commit...