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)
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.
-SteveZ
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);
}
Steve,
That should do it. I really appreciate your help. Thanks so much.
-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,
Would it be possible to use a hit test, as in this post? http://www.silverlightshow.net/Tips/ControlsAndUI-1.aspx