So I have a WPF data grid with about 8 cells in each row, I've only included the relevant one for simplicity but I'd like the user to be able to right click this cell and copy the contents into the windows clipboard without left clicking and selecting it first. I've tried many code snippets but can't seem to get anything to work. Each row is a binded item.
The majority of things I've been trying is with the MouseRightButtonDown event. Some have tried the to the XY position, some have used e.OriginalSource as FrameworkElement but I can't seem to get anything to work. Not sure if its because its a DataGridHyperlinkColumn as opposed to the other types used in the examples?
I'm a c# n00b! Any help would be greatly appreciated.
<DataGrid x:Name="eventsDataGrid" AutoGenerateColumns="False" IsReadOnly="true" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="10,143,0,0" VerticalAlignment="Top" Height="295" CanUserAddRows="False" CanUserReorderColumns="False" CanUserResizeColumns="True" CanUserSortColumns="False" BorderThickness="1" HorizontalScrollBarVisibility="Disabled" FontSize="10" Width="1003" MouseRightButtonDown="eventsDataGrid_MouseRightButtonDown">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy URL" Click="CopyURL">
</MenuItem>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Columns>
<DataGridHyperlinkColumn Width="230" Header="URL" Binding="{Binding URL}" CanUserResize="False">
<DataGridHyperlinkColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ToolTip" Value="URL of website" />
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</DataGridHyperlinkColumn.HeaderStyle>
<DataGridHyperlinkColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Foreground" Value="Black" />
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="FontSize" Value="12"/>
</Style>
</DataGridHyperlinkColumn.CellStyle>
</DataGridHyperlinkColumn>
</DataGrid.Columns>
</DataGrid>