I currently have code that shows a ContextMenu
upon right clicking. My problem however stems from the fact that the menu pops up when right clicking anywhere on the DataGrid
and not just the rows. Is there anyway to prevent this? i.e., have the ContextMenu
pop up only when right clicking a row.
// C#
private void updateBill(object sender, RoutedEventArgs e) {
Console.WriteLine("WORKS");
}
// XAML
<DataGrid x:Name="dgCash" HorizontalAlignment="Left" Margin="5,0,5,5" Grid.RowSpan="1" AutoGenerateColumns="False" IsReadOnly="True"
HorizontalContentAlignment="Right">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding denomination}" Header="Denomination"/>
<DataGridTextColumn Binding="{Binding start}" Header="Starting"/>
<DataGridTextColumn Binding="{Binding end}" Header="End of day"/>
<DataGridTextColumn Binding="{Binding deposit}" Header="Deposit" Width="*"/>
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Update Bill" Click="updateBill" />
</ContextMenu>
</DataGrid.ContextMenu>
</DataGrid>