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?
Hi Greg,
Yes that makes sense.
And i made a mistake before, the approach you originally suggested is probably the best approach, recycling wouldn't matter with that case, as you're hooking the event directly to the grid. Although, once you get a CellControl, using mouse over, i'd recommend that you access the Cell property off it, you plan to apply any sort of style to it, as opposed to the control itself, as thats where you'll run into recycling issues.
Using the second approach, where you using the cell's control directly won't work, as there isn't guaranteed to be a control attached to a cell at any given point in time. And this is the scenario which i originally assumed you were going to try, and would cause all kinds of recycling problems.
Btw, you would use Cells[0].Control, not Cells[0].Content.
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
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.