I have a 10x10 Grid
. And in each space I have added a label to which I added a mousedoubleclick event handler. So when I double click the label it's supposed to show the Row
and Column
number, but I only get 0 for both properties.
This is the code... (and yes I have set Grid.SetRow
and Grid.SetColumn
for each label)
private void grid_Checked(object sender, MouseButtonEventArgs e)
{
MessageBox.Show(Grid.GetRow(e.Source as UIElement).ToString());
}
You may need to use e.OriginalSource instead of e.Source. The checked event, being a routed event, will change
e.Source
as it routes through the tree.Are you sure that everything is hooked up correctly? The following works for me:
XAML:
C#:
The
MessageBox
contains the correct row and column when I click on one of the labels.