1

I've just noticed that the CanUserSortColumns attribute of the Silverlight 4 Toolkit DataGrid element doesn't seem to work when sourced with DateTime types. Every other type reacts as expected.

XAML snippet

<sdk:DataGrid Grid.Row="0"
    x:Name="FoobarDataGrid"
    DataContext="foobar"
    AutoGenerateColumns="False"
    CanUserReorderColumns="True"
    CanUserResizeColumns="True"
    CanUserSortColumns="True"
    IsReadOnly="True"
    Width="Auto"
    Height="Auto" Margin="8">
    <!-- row/column definitions here, skipped -->
    <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <sdk:DatePicker
                IsEnabled="False"
                UseLayoutRounding="True"
                SelectedDate="{Binding SomeWorkingBinding}"
                SelectedDateFormat="Short" />
        </DataTemplate>
    </sdk:DataGridTemplateColumn.CellTemplate>
    <!-- row/column definitions here, skipped --> 
</sdk:DataGrid>

What am I'm doing wrong?

1 Answer 1

1

For a DataGridTemplateColumn you need to specify the SortMemberPath by which the column (values) are sorted.

<sdk:DataGridTemplateColumn SortMemberPath="SomeWorkingBinding">
  <sdk:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <sdk:DatePicker
            IsEnabled="False"
            UseLayoutRounding="True"
            SelectedDate="{Binding SomeWorkingBinding}"
            SelectedDateFormat="Short" />
    </DataTemplate>
  </sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
1
  • it worked, thanks much for your contribution! -- so apparently one can sort by a criteria different than the bound data? interesting. Oct 4, 2011 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.