2010-02-16 2 views
2

myListBox.Items.SortDescriptions.Add ( ) 새 SortDescription ("BoolProperty", ListSortDirection.Descending));ICollectionView.SortDescriptions이 부울에 대해 작동하지 않습니다.

이 정렬은 기본 프로젝트의 문자열 속성에만 적용됩니다. 부울이 아닌가요? 그 이유가 있을까요?

감사합니다.

UPDATE :

그래, 당신의 예를 정말 작동합니다. 내 모범은 무엇이 잘못 되었습니까?

public class A 
{ 
    public bool Prop;    
} 

List<A> l = new List<A>() { 
    new A() { Prop = true }, 
    new A() { Prop = false }, 
    new A() { Prop = true }, 
}; 

ICollectionView icw = CollectionViewSource.GetDefaultView(l);             
icw.SortDescriptions.Add(new SortDescription("Prop", ListSortDirection.Ascending));     
icw.Refresh(); 

답변

3

흠, 내 목록 예의 부울 속성에 SortDescription을 추가하는 것처럼 보일 수 있습니다! 뒤에

<Window x:Class="WpfApplication3.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="300" Width="300"> 
    <Grid> 
     <ListBox x:Name="box" DisplayMemberPath="Test" /> 
    </Grid> 
</Window> 

코드 : 마법처럼

public partial class Window1 : Window 
{ 
    public Window1() 
    { 
     InitializeComponent(); 

     //4 instances, each with a property Test of another boolean value 
     box.ItemsSource = new[] { 
      new {Test = true}, 
      new {Test = false}, 
      new {Test = false}, 
      new {Test = true} 
     }; 

     box.Items.SortDescriptions.Add(new SortDescription("Test", ListSortDirection.Descending)); 
    } 
} 


public class BooleanHolder 
{ 
    public bool Test { get; set; } 
} 

작품)

이 아마도 당신이 SortDescription 객체의 속성 이름의 철자가 잘못? 희망이 도움이

예제에서 당신은 필드로 소품을 정의했습니다. 그것을 속성으로 만들면 성공할 것입니다.)

public class A 
{ 
    public bool Prop { get; set; } 
} 
+0

그래, 당신의 예제가 실제로 작동하지만, 제발 제발 봐, 나는 큰 차이가 없다. –

+0

재산은 재산이 아니라 필드입니다. 차이가 있습니다! ;) WPF가 속성을 찾고 찾지 못했습니다! – Arcturus

+0

그래, 그 차이를 깨달았다. .. 고마워, 필드는 어쨌든 사적인 것이어야한다. 아마도 그 이유는 ... –