2009-04-11 7 views
3

最初に私は非常に私の知識の大きなギャップがあるように私は非常にコーディングしていると言わせてください... anywho:ボタンクリック時にWPF ListBoxを並べ替えますか?

私は、ボタンをクリックしたときにWPFリストボックスをソートしようとしている純粋なxaml(それ以外の場合はVB)。ほとんどのサンプルがC#で書かれているので、私は見苦しいです。今

<Button x:Name="SortNameAsc" 
     Content="Sort By Name" 
     Visibility="Visible"> 

を、このボタンをクリックしたときに、私はフィールドでソートするリストボックスをたい:私は何をしたいので、同様にボタンを追加され、今

<Grid.Resources> 
     <CollectionViewSource x:Key="myCollectionView" 
          Source="{Binding Path=Query4, Source={x:Static Application.Current}}" > 
      <CollectionViewSource.SortDescriptions> 
       <scm:SortDescription PropertyName="ContactID" 
            Direction="Descending"/> 
      </CollectionViewSource.SortDescriptions> 
     </CollectionViewSource> 
</Grid.Resources> 

<ListBox x:Name="ContDefault" 
     IsSynchronizedWithCurrentItem="True" 
     ItemsSource="{Binding Source={StaticResource myCollectionView}}" 
     ItemTemplate="{StaticResource ContactsList}" /> 

:ここに私のコードです「ファーストネーム」は、何とか並べ替えの説明を変更しなければならないと思います。または、私はこのhte worng方法について行きます。もう一度XAMLでpreferabbly、しかしVBで必要な場合は試してみてくださいそれを簡単に保つことができます??

みんな

答えて

2

はそれが役に立てば幸いありがとう: Googleは実施例3に関しては、この(http://www.kudzuworld.com/blogs/Tech/20070815A.en.aspx

ListCollectionView view = new ListCollectionView(channel.Members); 
view.SortDescriptions.Add(new System.ComponentModel.SortDescription("lastName", 
    System.ComponentModel.ListSortDirection.Ascending); 
view.SortDescriptions.Add(new System.ComponentModel.SortDescription("firstName", 
    System.ComponentModel.ListSortDirection.Ascending); 
view.CustomSort = new IComprarerImplementation; //Do this if you want a custom sort; 
view.Refresh(); 

を思い付いた、これは正しいはずです:

<ListBox x:Name="ContDefault" 
     IsSynchronizedWithCurrentItem="True" 
     ItemsSource="{Binding Source={StaticResource myCollectionView}}" 
     ItemTemplate="{StaticResource ContactsList}" 
     SortDescription="First Name" /> 
は、
関連する問題