Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Selector::SelectedValue Property

Gets or sets the value of the SelectedItem, obtained by using SelectedValuePath.

Namespace:  System.Windows.Controls.Primitives
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

[BindableAttribute(true)]
[LocalizabilityAttribute(LocalizationCategory::NeverLocalize)]
public:
property Object^ SelectedValue {
	Object^ get ();
	void set (Object^ value);
}
<object>
  <object.SelectedValue>
    <Object .../>
  </object.SelectedValue>
</object>

Property Value

Type: System::Object
The value of the selected item.

The SelectedValuePath property specifies the path to the property that is used to determine the value of the SelectedValue property. Setting SelectedValue to a value X attempts to select an item whose value evaluates to X; if no such item can be found, the selection is cleared.

The following example binds a ListBox to a collection of Employee objects. The example sets SelectedValuePath to @EmployeeNumber and SelectedValue to 12345. This selects the Employee that has 12345 as the value of EmployeeNumber. This example also binds a TextBlock to the SelectedValue of the ListBox. When the user changes the selection in the ListBox, the TextBlock is updated to show the employee number of the currently selected employee.

<XmlDataProvider x:Key="Employees" XPath="/Employees/*">
  <x:XData>
    <Employees xmlns="">
      <Employee Name="Terry Adams" Type="FTE" EmployeeNumber="1" />
      <Employee Name="Claire O&apos;Donnell" Type="FTE" EmployeeNumber="12345" />
      <Employee Name="Palle Peterson" Type="FTE" EmployeeNumber="5678" />
      <Employee Name="Amy E. Alberts" Type="CSG" EmployeeNumber="99222" />
      <Employee Name="Stefan Hesse" Type="Vendor" EmployeeNumber="-" />
    </Employees>
  </x:XData>
</XmlDataProvider>

<DataTemplate x:Key="EmployeeItemTemplate">
  <TextBlock Text="{Binding XPath=@Name}" />
</DataTemplate>


...


    <ListBox Name="employeeListBox"
             ItemsSource="{Binding Source={StaticResource Employees}}"
             ItemTemplate="{StaticResource EmployeeItemTemplate}"
             SelectedValue="12345"
             SelectedValuePath="@EmployeeNumber"/>

    <TextBlock Text="{Binding ElementName=employeeListBox, 
                      Path=SelectedValue}"/>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft