设置default / init列以在Silverlight中进行排序

时间:2012-08-23 12:44:37

标签: .net silverlight xaml sorting datagrid

我发现很多线程都带有上面的关键字,但大多数人都要求排序。我要求在初始化时刻排序。如果加载了表单,GridView应该已经按特定列排序。如果可能的话,在XAML中。

现在默认情况,我不需要: The current loaded situation

加载表单时我想要的默认情况: XAML default sorting in Silverlight

知道怎么做吗?

<sdk:DataGrid x:Name="dgv" 
                          ItemsSource="{Binding}"

                          >
            <sdk:DataGrid.Resources>
                <CollectionViewSource x:Key="PrioritySorter" Source="{Binding .}">
                    <CollectionViewSource.SortDescriptions>
                        ????? How to sort by "Active" property ASC?
                    </CollectionViewSource.SortDescriptions>
                </CollectionViewSource>
            </sdk:DataGrid.Resources>

            <sdk:DataGrid.Columns >
                <sdk:DataGridTextColumn         
                    Header="N°"         
                    Binding="{Binding Id}"              
                    IsReadOnly="True"/>

            <sdk:DataGrid.Columns >
                <sdk:DataGridTextColumn         
                    Header="Priority"         
                    Binding="{Binding Priority}"  />


            <sdk:DataGrid.Columns >
                <sdk:DataGridTextColumn         
                    Header="Active"         
                    Binding="{Binding Id}"  />

*解决方案*

Private Sub Service_GetItemsCompleted(sender As Object, e As ServiceReference1.GetItemsCompletedEventArgs) Handles Service.GetItemsCompleted
    'Me.Items = e.Result
    Dim pageView As New PagedCollectionView(e.Result)
    pageView.SortDescriptions.Add(New SortDescription("Rights", ListSortDirection.Ascending))
    Me.dgv1.DataContext = pageView
End Sub

0 个答案:

没有答案