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?
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 nice code. However, what reference do I use to get to the Popup class?
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