按标题问题排序WPF MVVM

时间:2014-02-11 17:10:02

标签: c# wpf sorting mvvm

我在2个不同的视图中有2个DataGrids。两个网格都设置为:

CanUserSort = "True"

Grid1按用户点击列标题进行排序。然而,Grid2在某些列上排序,而在其他列上排序。例如,我有一个ID列,值在页面加载时排序:

1 2 3 4 5

当点击标题排序时,它们会回来:

2 4 五 1 3

我还试过SortMemberPath="ColumnName"

<DataGrid AutoGenerateColumns="False" Height="233" HorizontalAlignment="Left" Margin="10,10,0,0" Name="PublicationsDataGrid" IsReadOnly="True" VerticalAlignment="Top" Width="1236" ItemsSource="{Binding Path=ModelPublicationsObservableList}"
                  SelectedItem="{Binding ModelSelectedPublication}" SelectionMode="Single">
        <DataGrid.Columns>
            <DataGridTextColumn x:Name="PublicationIdColumn" Binding="{Binding Path=PublicationId}" Header="PublicationId" Width="80"/>
            <DataGridTextColumn x:Name="PublicationTitleColumn" Binding="{Binding Path=PublicationTitle}" Header="PublicationTitle" Width="350" />
            <DataGridTextColumn x:Name="PublicationTypeColumn" Binding="{Binding Path=PublicationType}" Header="PublicationType" Width="253" />
            <DataGridTextColumn x:Name="ProductCodeColumn" Binding="{Binding Path=ProductCode}" Header="ProductCode" Width="216" />
            <DataGridTextColumn x:Name="dateCreatedColumn" Binding="{Binding Path=DateCreated, StringFormat={}\{0:dd/MM/yyyy HH:mm\}}" Header="DateCreated" Width="SizeToHeader" />                
            <DataGridTextColumn x:Name="userCreatedColumn" Binding="{Binding Path=userCreated}" Header="UserCreated" Width="SizeToHeader" />
            <DataGridTextColumn x:Name="dateUpdatedColumn" Binding="{Binding Path=dateUpdated}" Header="DateUpdated" Width="SizeToHeader" />
            <DataGridTextColumn x:Name="userUpdatedColumn" Binding="{Binding Path=userUpdated}" Header="UserUpdated" Width="SizeToHeader" />
        </DataGrid.Columns>

    </DataGrid>

有什么想法吗?感谢

1 个答案:

答案 0 :(得分:0)

认为我找到了罪魁祸首。排序不适用于整数值&lt; 10.我已将表格中的ID更改为0000001等等,一切都很好