I got a Grid with controls such System.Windows.Controls.Image and Labels in each RowDefinition of my Grid. The problem is when I do the right click contextmenu it works and I can get the grid back but I cannot get the Row which the click occurred.
- I do not know what UIElement is being clicked on as I want the user to be able to click on any element within the row boundaries.
Here is what I have already,
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Open Client CP" Background="#FF1C1C1C"/>
<MenuItem Header="Auto Mine" Background="#FF1C1C1C"/>
<MenuItem Header="Disconnect" Background="#FF1C1C1C"/>
<MenuItem Header="Uninstall" Background="#FF1C1C1C"/>
<MenuItem Header="Refresh" Background="#FF1C1C1C" Click="onRefreshMenuClick" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Parent}"/>
</ContextMenu>
</Grid.ContextMenu>
private void onRefreshMenuClick(object sender, RoutedEventArgs e)
{
MenuItem mi = sender as MenuItem;
if (mi != null)
{
ContextMenu cm = mi.CommandParameter as ContextMenu;
if (cm != null)
{
Grid g = cm.PlacementTarget as Grid;
if (g != null)
{
// need something here like g.getrowof(cm.placementtarget)
if (debugWindow != null)
debugWindow.LogTextBox.AppendText("Requested refresh from "+ row);
}
}
}
}
maybe something like this?:
You can hit test for
DataGridRow
, given mouse position & the Grid.http://msdn.microsoft.com/en-us/library/ms752097.aspx (Hit Testing in the Visual Layer)