开发者

Silverlight 4 Toolkit DataGrid's CanUserSortColumns attribute not working on DateTime types

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="{Bi开发者_运维百科nding SomeWorkingBinding}"
                SelectedDateFormat="Short" />
        </DataTemplate>
    </sdk:DataGridTemplateColumn.CellTemplate>
    <!-- row/column definitions here, skipped --> 
</sdk:DataGrid>

What am I'm doing wrong?


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>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜