SelectedValue and SelectedValuePath in Silverlight 4


Introduction

In this article we will see about SelectedValue and SelectedValuePath while Binding. This feature is added in Silverlight 4.

SelectedValue and SelectedValuePath

These properties enable a ComboBox to behave as a look up table, that means a value can be displayed in ComboBox but when selected another property would be selected.

Let's do a sample where we can see it.

Let's have a ComboBox to display the data and a TextBlock which will display another property of the bound data of ComboBox.

Let's have sample data which can be bound to ComboBox.

image1.gif

The above class represents a sample Employee Entity structure.

image2.gif

Now in xaml we need to do proper binding as follows:

image3.gif

As you see in above xaml display, we have set the SelectedValuePath which is different from the displaying Path. In our case SelectedValuePath is "EmailID" and for display it is "EmployeeName".

In the TextBlock, the Text property is bound to the SelectedValue of the Element ComboBox.

Now let's run the application and see the Properties in action.

image4.gif

That's it. It's easy in Silverlight 4 to use SelectedValue and SelectedValuePath for displaying one property and displaying another property on selection.

Hope this article helps. 

Up Next
    Ebook Download
    View all
    Learn
    View all