Up Display code samples
DevForce 2010 Resource Center » Code samples » Display code samples » Code sample: Simple combo box (Silverlight)

Code sample: Simple combo box (Silverlight)

Last modified on August 15, 2012 17:21

This sample shows how to use a bound combo box control in a Silverlight application.


Problem

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?

Solution

This sample shows how to set up the combo box bindings in a Silverlight application.  

Here's the simple form:

slcombo2.JPG

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!

Created by DevForce on May 03, 2011 09:11

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade