2010-03-25 1 views
1

두 개의 Silverlight 4.0 ComboBox가 있습니다. 두 번째 표시 처음에 선택한 개체의 어린이 :WCF RIA, Entity Framework 4, Silverlight 4를 사용하는 관용적 기본 정렬?

<ComboBox 
    Name="cmbThings" 
    ItemsSource="{Binding Path=Things,Mode=TwoWay}" 
    DisplayMemberPath="Name" 
    SelectionChanged="CmbThingsSelectionChanged" /> 
<ComboBox 
    Name="cmbChildThings" 
    ItemsSource="{Binding Path=SelectedThing.ChildThings,Mode=TwoWay}" 
    DisplayMemberPath="Name" /> 

뷰 뒤에 코드가 엔티티 프레임 워크에게 WCF RIA 서비스를 통해 4.0 엔티티를로드하여, 그 선택 상자를 데이터 바인딩하는 (단순, 해키) 방법을 제공합니다 : 내가하고 싶은 무엇

public EntitySet<Thing> Things { get; private set; } 
public Thing SelectedThing { get; private set; } 

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    var context = new SortingDomainContext(); 
    context.Load(context.GetThingsQuery()); 
    context.Load(context.GetChildThingsQuery()); 
    Things = context.Things;    
    DataContext = this; 
} 

private void CmbThingsSelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    SelectedThing = (Thing) cmbThings.SelectedItem; 
    if (PropertyChanged != null) 
    { 
     PropertyChanged.Invoke(this, new PropertyChangedEventArgs("SelectedThing")); 
    } 
} 

public event PropertyChangedEventHandler PropertyChanged; 

은 알파벳 순으로 정렬 내용을 모두 콤보 상자를, 그리고 나는 가능한 모든 경우 XAML에 그 동작을 지정하고 싶습니다.

누군가 SL4/EF4/WCF RIA 기술 스택을 사용하여 이것을 수행하는 관용적 인 방법을 말해 줄 수 있습니까?

답변

0

CollectionViewSource을 사용하여 콤보 박스에 연결하십시오. CollectionViewSource는 정렬, 그룹화 및 필터링을 제공합니다.

CollectionViewSource의 출처로 EntitySet을 설정하십시오. CollectionViewSource는 모든 컨트롤의 Resources-Section에 추가 할 수 있습니다.

<CollectionViewSource Source="{StaticResource Things}" x:Key="cvs"> <!--The source can be set in procedural code--> 
    <CollectionViewSource.SortDescriptions> 
    <scm:SortDescription PropertyName="Name"/> <!--The name of the property to sort items--> 
    </CollectionViewSource.SortDescriptions> 
</CollectionViewSource> 

<!--The prefix scm mappes to the System.ComponentModel--> 

테스트 해 보았지만 제대로 작동하지 않았습니다. CollectionViewSource의 Property Source는 object 유형입니다. 해당 개체가 IEnumerable과 같은 지정된 인터페이스를 구현해야하는지 여부는 알 수 없습니다.

+0

감사합니다. 여기에 CollectionViewSource에 대한 빠른 자습서도 있습니다. http://bea.stollnitz.com/blog/?p=17 –