开发者

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

开发者 https://www.devze.com 2023-04-10 21:39 出处:网络
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.

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

精彩评论

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

关注公众号