I am desinging a wpf application. I code a grid(which has 35 textblocks)-wide context menu. when I click mouse's right button I need to learn on which textblock I clicked. But click event gives centext menu as a sender. How can I reach on which textblock the user click right mouse button?
My XAML code---------------------------------------------------------------:
<Grid>
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Hafta İçi" x:Name="btnWeekDay" Click="btnWeekDay_Click" />
<MenuItem Header="Cuma" x:Name="btnFriday" Click="btnFriday_Click"/>
<MenuItem Header="Cumartesi" x:Name="btnSaturday" Click="btnSaturday_Click"/>
<MenuItem Header="Pazar" x:Name="btnSunday" Click="btnSunday_Click"/>
<MenuItem Header="İdari İzin" x:Name="btnAdminLeave" Click="btnAdminLeave_Click"/>
<MenuItem Header="Bayram/Tatil" x:Name="btnHoliday" Click="btnHoliday_Click" a/>
</ContextMenu>
</Grid.ContextMenu>
My C# code-------------:
private void btnWeekDay_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(sender + e.Source.ToString());
}
OriginalSourceproperty? - ClemensClick, notMouseRightButtonDown. There is also noTextBlockto be seen anywhere in your code. Please provide a good minimal reproducible example that reliably reproduces the issue. Note that with theContextMenuattached to theGrid, it's theGridhandling the mouse event that opens the context menu. You might want to consider styling your grid items so that each of them actually owns a context menu. - Peter Duniho