2013-09-06 2 views
1

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"> 
+0

이것은 무엇입니까? "Source ="{Binding Items, ElementName = Selector} " –

+0

Items가 내 ViewModel의 컬렉션입니다. – UCFLaura

+0

LiveSortingProperties 컬렉션을 제외하고 (여전히 IsLiveSortingRequested를 true로 설정 한 경우) 기본적으로 SortDescriptions의 속성을 사용합니다 .. – Govert

답변

0

, 당신은 Checkbox.IsChecked 특성 bool 속성을 바인딩? 그렇다면 SortDescription.PropertyName 속성으로 설정할 수 있어야합니다. 인 것처럼 보입니다. 그렇지 않다면 입니다.

+0

yes 내 Checkbox.IsChecked는 IsSelected 속성에 바인딩됩니다. – UCFLaura

관련 문제