Export (0) Print
Expand All

TreeView.SelectedValuePath Property

Gets or sets the path that is used to get the SelectedValue of the SelectedItem in a TreeView.

Namespace:  System.Windows.Controls
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)]
public string SelectedValuePath { get; set; }
<object SelectedValuePath="string" .../>

Property Value

Type: System.String
A string that contains the path that is used to get the SelectedValue. The default value is String.Empty.

Identifier field

SelectedValuePathProperty

Metadata properties set to true

None

The SelectedValuePath property specifies the path to the property that is used to determine the value of the SelectedValue property. For example, assume that a TreeView is bound to a collection of objects of type Employee, which has two properties called EmployeeName and EnployeeNumber. You can use a HierarchicalDataTemplate to display the value of EmployeeName in the TreeView and set SelectedValuePath to "EmployeeNumber" to have SelectedValue return the value of EmployeeNumber.

The following example shows a TreeView that uses a HierarchicalDataTemplate to display the EmployeeName and EmployeeWorkDay properties of an Employee and sets the SelectedValue property to the EmployeeNumber. When you select an EmployeeName in the TreeView, the SelectedValue is set to the EmployeeNumber.

    <TreeView ItemsSource="{Binding Source={StaticResource myEmployeeData}, 
        XPath=EmployeeInfo}" 
        Name="myTreeView" 
        SelectedValuePath="EmployeeNumber" 
        />

    <TextBlock Margin="10">SelectedValuePath: </TextBlock>
    <TextBlock Margin="10,0,0,0" 
               Text="{Binding ElementName=myTreeView, 
                              Path=SelectedValuePath}"
               Foreground="Blue"/>

    <TextBlock Margin="10">SelectedValue: </TextBlock>
    <TextBlock Margin="10,0,0,0" 
               Text="{Binding ElementName=myTreeView, 
                              Path=SelectedValue}"
               Foreground="Blue"/>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft