Bagikan melalui


TreeView.SelectedValue Properti

Definisi

Mendapatkan nilai properti yang ditentukan oleh SelectedValuePath untuk SelectedItem.

public:
 property System::Object ^ SelectedValue { System::Object ^ get(); };
[System.ComponentModel.Bindable(true)]
public object SelectedValue { get; }
[<System.ComponentModel.Bindable(true)>]
member this.SelectedValue : obj
Public ReadOnly Property SelectedValue As Object

Nilai Properti

Nilai properti yang ditentukan oleh SelectedValuePath untuk SelectedItem, atau null jika tidak ada item yang dipilih. Nilai defaultnya adalah null.

Atribut

Contoh

Contoh berikut menunjukkan TreeView yang menggunakan HierarchicalDataTemplate untuk menampilkan EmployeeName properti dan EmployeeWorkDay dari dan Employee mengatur SelectedValue properti ke EmployeeNumber. Saat Anda memilih EmployeeName di TreeView, SelectedValue diatur ke 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"/>

Keterangan

Properti SelectedValuePath menentukan jalur ke properti yang digunakan untuk menentukan nilai properti SelectedValue. Misalnya, asumsikan bahwa terikat TreeView ke kumpulan objek jenis Employee, yang memiliki dua properti yang disebut EmployeeName dan EmployeeNumber. Anda dapat menggunakan HierarchicalDataTemplate untuk menampilkan nilai EmployeeName dalam TreeView dan diatur SelectedValuePath ke "EmployeeNumber" untuk mengembalikan SelectedValue nilai EmployeeNumber.

Properti SelectedValue adalah properti baca-saja. Untuk mengubah nilai item yang dipilih dalam TreeView, gunakan SelectedItem properti untuk mengakses TreeViewItem.

Informasi Properti Dependensi

Item Nilai
Bidang pengidentifikasi SelectedValueProperty
Properti metadata diatur ke true Tidak

Berlaku untuk

Lihat juga