TreeView.SelectedValuePath 属性

定义

获取或设置用于获取 SelectedValueSelectedItemTreeView 的路径。

public:
 property System::String ^ SelectedValuePath { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string SelectedValuePath { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.SelectedValuePath : string with get, set
Public Property SelectedValuePath As String

属性值

String

一个字符串,其中包含用于获取 SelectedValue 的路径。 默认值是 String.Empty

属性

示例

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. 在选择一个EmployeeNameTreeView时,将SelectedValue设置为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"/>

注解

SelectedValuePath 属性指定用于确定属性值 SelectedValue 的属性的路径。 例如,假设一个 TreeView 绑定到类型 Employee为对象的集合,该集合调用 EmployeeName 了两个属性和 EmployeeNumber。 可以使用 a 显示值,并将该值设置为SelectedValue "EmployeeNumber" SelectedValuePath返回值。EmployeeNumberTreeView EmployeeName HierarchicalDataTemplate

依赖项属性信息

标识符字段 SelectedValuePathProperty
元数据属性设置为 true

适用于

另请参阅