0
現在、名前でItemsControl
をソートしようとしています。現在、私はリストを印刷していますが、Views側では注文できないようです。私は、コントロールまたはモデル側でそれを注文することができますが、それはビューから動作するようにします。WPF Sort ItemsControlバインディング
My ItemsControl
には、AllJobTypes(クラスJobTypes
のリスト)へのバインディングがあります。 JobTypes
にはName
という名前のプロパティがあります。このプロパティはビューで並べ替えたいものです。
私は、各オブジェクトのカウントを出力するXAMLにデバッグコードをいくつか持っています。最初の2枚が「失敗」し、最後のプリントが正しく機能します。ビュー側にAllJobTypes
を注文するにはどうすればよいですか?
<UserControl.Resources>
<converters:JobTypeCreditUnionCountConverter x:Key="JobTypeCreditUnionCountConverter" />
<CollectionViewSource x:Key="cvs" Source="{Binding RelativeSource={RelativeSource
AncestorType=UserControl}, Path=AllJobTypes}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Name"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</UserControl.Resources>
<StackPanel>
<Label Foreground="SteelBlue" FontSize="20" FontWeight="Bold">Job Types</Label>
<Label Content="{Binding AllJobTypes.Count, FallbackValue='fail'}" /> //Fail
<Label Content="{Binding cvs.Count, FallbackValue='fail'}" /> //Fail
<Label Content="{Binding RelativeSource={RelativeSource
AncestorType=UserControl}, Path=AllJobTypes}" /> //(Collection
<ItemsControl ItemsSource="{Binding cvs}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="" />
<TextBox Grid.Column="1" Text="{Binding Name}" IsEnabled="False" />
3時間前、あなたは ''のItemsSource = "{バインディングソース= {StaticResourceのCVS}}" との答えを受け入れました。なぜあなたは今それとは違うのですか? – Clemens