I have a Treeview in my WPF application. I need to copy the elements in my treeview.
private void copyCmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
// Set text to clip board
TreeView tvi = (TreeView)sender;
Clipboard.SetText(tvi.SelectedValue.ToString());
}
But here the tvi.SelectedValue wouldn’t return the text which i selected in my treeview. How can i get the text value i selected in my treeview.
Update:
<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>
try this:
in general this code may be useful: