What is the best way to add ‘copy to clipboard’ functionality to a ListView control in WPF?
I tried adding an ApplicationCommands.Copy to either the ListView ContextMenu or the ListViewItem ContextMenu, but the command remains disabled.
Thanks, Peter
Here is an xaml sample of one of my attempts…
<Window.Resources> <ContextMenu x:Key='SharedInstanceContextMenu' x:Shared='True'> <MenuItem Header='Copy' Command='ApplicationCommands.Copy'/> </ContextMenu> </Window.Resources> <ListBox Margin='12,233,225,68' Name='listBox1' > <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text='{Binding Path=UpToSourceCategoryByCategoryId.Category}' ContextMenu='{DynamicResource ResourceKey=SharedInstanceContextMenu}'/> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
How should I set the CommandTarget in this case?
Thanks,Peter
It looks like you need a CommandBinding.
Here is how I would probably go about doing what you trying to do.