我的 WPF 应用程序中有一个Treeview
。我需要复制树视图中的元素。
private void copyCmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
// Set text to clip board
TreeView tvi = (TreeView)sender;
Clipboard.SetText(tvi.SelectedValue.ToString());
}
但是这里tvi.SelectedValue
不会返回我在树视图中选择的文本。如何获取我在treeview
.
更新:
<TreeView Grid.Column="0" Grid.Row="0"
HorizontalAlignment="Stretch" Name="treeView1"
SelectedItemChanged="treeView1_SelectedItemChanged">
<TreeView.CommandBindings>
<CommandBinding Command="ApplicationCommands.Copy"
Executed="copyCmdBinding_Executed"
CanExecute="copyCmdBinding_CanExecute"/>
</TreeView.CommandBindings>
//Tree elements
</TreeView>