I'm trying to add Context Menu to MapPolylines and somehow it is not displaying the context menu. My requirement is to Right Click on MapPolyline and select Hide Polyline from Context Menu. Please see the code below:
Registering this event when drawing Polyline
private void techpolyline_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
MapPolyline rightClickPolyline;
ContextMenu mainMenu = new ContextMenu();
mainMenu.Background =
Brushes.LightBlue;
mainMenu.Height = 50;
mainMenu.Width = 120;
MenuItem baseItem = new MenuItem();
baseItem.Width = 120;
baseItem.Header =
"Select Action";
baseItem.Background =
Brushes.Blue;
baseItem.Foreground =
Brushes.White;
baseItem.FontWeight =
FontWeights.Bold;
mainMenu.Items.Add(baseItem);
MenuItem hidepolygonItem = new MenuItem();
hidepolygonItem.Width = 120;
hidepolygonItem.Header =
"Hide Polyline";
mainMenu.Items.Add(hidepolygonItem);
//hidepolygonItem.PreviewMouseLeftButtonDown +=new MouseButtonEventHandler(hidepolygonItem_PreviewMouseLeftButtonDown);
if (sender.GetType() == typeof(MapPolyline))
{
rightClickPolyline = (
MapPolyline)sender;
rightClickPolyline.ContextMenu = mainMenu;
}
}
I use the same logic to MapPinPoint items and Pushpin items and it works. Any help is appreciated.
Regards!!
Paddy