Silverlight数据网格无法对日期列进行排序

时间:2014-05-30 12:18:32

标签: c# silverlight datagrid

看到这个链接似乎是同一个问题:

There is no possibility to sort a date column in DataGrid

并且有响应"尝试设置SortMemberPath。"

不幸的是,我不知道该怎么做!我按照MSDN上属性帮助页面的链接,但没有澄清任何内容。这是我的xaml:

        <sdk:DataGrid x:Name="dg_ReferralsTS" Margin="5,5,0,25"  AutoGenerateColumns="False" CanUserSortColumns="True" Grid.Row="1" VerticalAlignment="Stretch" MaxHeight="{Binding ElementName=reportsRow1, Path=Height.Star, Mode=OneWay}"  >
        <sdk:DataGrid.Columns>
            <sdk:DataGridTemplateColumn x:Name="show_On_ChartColumn" Header="Show On Chart" Width="SizeToHeader">
                <sdk:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate >
                        <CheckBox x:Name="chkBox_ShowReferrals" HorizontalAlignment="Center" Tag="{Binding Path=referral.File_Reference}"  IsChecked="{Binding Path=isChecked, Mode=TwoWay}" Checked="chk_ShowReferral_Checked" Unchecked="chk_ShowReferral_Unchecked" />
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellTemplate>
            </sdk:DataGridTemplateColumn>
            <sdk:DataGridTextColumn x:Name="file_ReferenceColumn" SortMemberPath="referral.File_Reference" Binding="{Binding Path=referral.File_Reference, Mode=OneWay}" Header="File Reference" IsReadOnly="True" Width="SizeToHeader" />
            <sdk:DataGridTemplateColumn x:Name="DateToday_DateColumn" Header="Date Today" Width="120" CanUserSort="True" SortMemberPath="referral.Date_Today">
                <sdk:DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <sdk:DatePicker SelectedDate="{Binding Path=referral.Date_Today, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}" />
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellEditingTemplate>
                <sdk:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=referral.Date_Today, StringFormat=\{0:d\}}"/>
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellTemplate>
            </sdk:DataGridTemplateColumn>
            <sdk:DataGridTextColumn x:Name="latitudeColumn" Binding="{Binding Path=referral.Latitude}" Header="Latitude" Width="SizeToHeader"  />
            <sdk:DataGridTextColumn x:Name="longitudeColumn" Binding="{Binding Path=referral.Longitude}" Header="Longitude" Width="SizeToHeader" />
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>

2 个答案:

答案 0 :(得分:0)

尝试替换

SortMemberPath="referral.Date_Today"

使用

SortMemberPath="Date Today"

答案 1 :(得分:0)

当它是DataGridTemplateColumn时,您需要设置SortMemberPath,并且必须将CanUserSort属性设置为true。

(即CanUserSort="True" SortMemberPath="Date_Today"