This sample shows how to use a bound combo box control in a Silverlight application.
The combo box control presents a challenge: How do you bind a combo box to a collection of objects, and then bind a property from the selected object to some other scalar property?
This sample shows how to set up the combo box bindings in a Silverlight application.
Here's the simple form:
The meat of the binding is this:
XAML | <ComboBox Grid.Row="3" Grid.Column="1" x:Name="Manager" ItemsSource="{Binding VM.CandidateManagers, Mode=TwoWay, Source={StaticResource ViewModelLocator}}" SelectedItem="{Binding Manager, Mode=TwoWay}" /> |
The ItemsSource is bound to a list of entities, in this case "potential managers". The list also includes a null entity since the selection is optional.
The SelectedItem is bound to a scalar navigation property on the current item. When the SelectedItem changes that change is pushed into the navigation property, in this case Employee.Manager.
The sample also shows simple MVVM in action, along with design-time data. Check it out!