When a user hovers over a cell or row in my grid, I need to be able to attach my own custom event handler. Is this possible? Is it possible in some other way to know which row/cell they are hovering over (short of measuring the x/y coordinates on Grid.MouseEnter, which I already know I can do, but it's messy)
Hi,
We don't offer events for this. However, you'll need to be careful with the approach you're proposing, b/c as you scroll those cell and row controls. they will be reused for other cells and rows as part of the recycling engine.
What are you trying to accomplish?
Maybe i can suggest another way to achieve what you're looking to do.
-SteveZ
Hi - thanks for your response.
It's kind of complicated, but I'll do my best to explain.
Our UI starts out with a list view, and when you click on a record, we shrink down the list view to one or two columns on the left with the detail showing in another pane on the right. When the user mouses over the left hand list view in this split mode we gray out the detail pane on the right and want to effectively show the rest of the mouseover record. What I've done is create another xamWebGrid in the right hand pane that shows the remainder of the columns for the row the user is mousing over in the left hand side... make sense?
So how to I get the Cell/Row that is being hovered over (other than measuring the x/y coordinates? I'm not really clear on that part.
Thanks,
-greg
Hi Greg,
That article is pretty old, as the UIElement.HitTest method does not exist in Silverlight. Instead, you can use the VisualTreeHelper.FindElementsInHostCoordinates
IEnumerable<UIElement> elements = VisualTreeHelper.FindElementsInHostCoordinates(new Point(x, y), this._panel);
CellsPanel cellsPanel = null;
foreach (UIElement elem in elements)
{
cellsPanel = elem as CellsPanel;
if (cellsPanel != null)
break;
}
In the code above, a CellsPanel represents a Row's control. And it has a Row property associated with it. If you need a Cell, then look for a CellControl.
Hope this helps,
Steve,
That should do it. I really appreciate your help. Thanks so much.
And so is _panel the container of the xamWebGrid and the point object build off the location of the xamWebGrid's container?
private void xamGrid_MouseMove(object sender, MouseEventArgs e) {
Point position = e.GetPosition(GridContainer);
Ah, sorry, should have been more, clear. You should be able to pass in the the xamWebGrid to the FindElementsInHostCoordinates method and into e.GetPosition.