Idiomatic default sort using WCF RIA, Entity Framework 4, Silverlight 4?
- by Duncan Bayne
I've got two Silverlight 4.0 ComboBoxes; the second displays the children of the entity selected in the first:
<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" />
The code behind the view provides a (simple, hacky) way to databind those ComboBoxes, by loading Entity Framework 4.0 entities through a WCF RIA service:
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;
What I'd like to do is have both combo boxes sort their contents alphabetically, and I'd like to specify that behaviour in the XAML if at all possible.
Could someone please tell me what is the idiomatic way of doing this with the SL4 / EF4 / WCF RIA technology stack?