I am trying to get a silverlight popup to display near the mouse when I hover over a map element.
Is there a way of getting the mouse position from the elements symbol position?
that is the only way to get the mouse position for now, since the ElementHover EventArgs do not contain that information.
you can enter a feature request here: http://devcenter.infragistics.com/protected/requestfeature.aspx
If use MouseMove event, will it slow down the silverlight page and have bad performance.
David Negley"] this is not exposed as a feature of the map; however, you can use the RenderTransform of the Map Viewport's RootCanvas to translate the coordinate. private void XamWebMap_ElementHover(object sender, MapElementHoverEventArgs e) { XamWebMap theMap = (XamWebMap)sender; Point pos = e.Element.ActualSymbolOrigin; pos = theMap.Viewport.RootCanvas.RenderTransform.Transform(pos); Popup pop = new Popup(); pop.Child = new TextBlock() { Text = "hello" }; pop.HorizontalOffset = pos.X; pop.VerticalOffset = pos.Y; pop.IsOpen = true; } alternatively, you could just use the MouseMove event, and avoid referencing any MapElement.
this is not exposed as a feature of the map; however, you can use the RenderTransform of the Map Viewport's RootCanvas to translate the coordinate.
private void XamWebMap_ElementHover(object sender, MapElementHoverEventArgs e) { XamWebMap theMap = (XamWebMap)sender; Point pos = e.Element.ActualSymbolOrigin; pos = theMap.Viewport.RootCanvas.RenderTransform.Transform(pos); Popup pop = new Popup(); pop.Child = new TextBlock() { Text = "hello" }; pop.HorizontalOffset = pos.X; pop.VerticalOffset = pos.Y; pop.IsOpen = true; }
alternatively, you could just use the MouseMove event, and avoid referencing any MapElement.
These codes populate the position of that element, it's not exactly the position of mouse.
How could I get exactly the position of mouse?
Popup is in System.Windows.Controls.Primitives in the System.Windows.dll assembly which you probably already have referenced. A quick way to find a type that you are looking for is to search in object browser:
Or filling out a missing namespace will usually be an autocorrect option in studio intellisense. Hover over the typename until you get the error drop down and select the option that adds the correct import statement.
-Graham
This is nice code. However, what reference do I use to get to the Popup class?