SelectedValue and SelectedValuePath in Silverlight 4

0 comments
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.
READ MORE >> http://www.c-sharpcorner.com/UploadFile/dpatra/1092/

0 comments: