CollectionViewSource를 통해 바인딩 된 ListBox를 포함하는 사용자 정의 컨트롤을 만들었습니다. ListBox에는 사용자가 여러 항목을 선택할 수있는 CheckBox가 있습니다. 선택한 CheckBox를 맨 위에 정렬하여 목록을 정렬하고 싶습니다. 나는 사용자가 뭔가를 선택하거나 선택을 취소하자마자 바로이 작업을하기를 희망한다. 나는 xaml을 통해 이것을하는 것을 발견 할 수 없다. 내가 도대체 뭘 잘못하고있는 겁니까? 내 XAMLCollectionViewSource 라이브 정렬이 작동하지 않습니다.
<CollectionViewSource x:Key="SortedItems"
Source="{Binding Items, ElementName=Selector}"
IsLiveSortingRequested="True">
<CollectionViewSource.LiveSortingProperties>
<System:String>IsSelected</System:String>
</CollectionViewSource.LiveSortingProperties>
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="IsSelected"
Direction="Descending" />
<scm:SortDescription PropertyName="CodeDescriptionText" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
에서
내 목록 상자 당신의 ItemTemplate
에서
<ListBox x:Name="ItemsControl"
SelectionMode="Multiple"
ItemsSource="{Binding Source={StaticResource SortedItems}}"
ItemTemplate="{Binding ItemTemplate, ElementName=Selector}"
ItemContainerStyle="{StaticResource ListBoxItemStyle}"
Grid.Row="1"
Grid.ColumnSpan="3">
이것은 무엇입니까? "Source ="{Binding Items, ElementName = Selector} " –
Items가 내 ViewModel의 컬렉션입니다. – UCFLaura
LiveSortingProperties 컬렉션을 제외하고 (여전히 IsLiveSortingRequested를 true로 설정 한 경우) 기본적으로 SortDescriptions의 속성을 사용합니다 .. – Govert