ContextMenu on MapPolylines does not work

2 posts, 0 answers
  1. Padmanabhan
    Padmanabhan avatar
    4 posts
    Member since:
    Jan 2011

    Posted 18 Feb 2011 Link to this post


       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 =





    mainMenu.Height = 50;


    mainMenu.Width = 120;




    MenuItem baseItem = new MenuItem();



    baseItem.Width = 120;


    baseItem.Header =


    "Select Action";



    baseItem.Background =





    baseItem.Foreground =





    baseItem.FontWeight =











    MenuItem hidepolygonItem = new MenuItem();



    hidepolygonItem.Width = 120;


    hidepolygonItem.Header =


    "Hide Polyline";







    //hidepolygonItem.PreviewMouseLeftButtonDown +=new MouseButtonEventHandler(hidepolygonItem_PreviewMouseLeftButtonDown);




    if (sender.GetType() == typeof(MapPolyline))





      rightClickPolyline = (





      rightClickPolyline.ContextMenu = mainMenu;





    I use the same logic to MapPinPoint items and Pushpin items and it works. Any help is appreciated.

  2. Andrey
    Andrey avatar
    1681 posts

    Posted 23 Feb 2011 Link to this post

    Hi Padmanabhan,

    Presently, the map shape objects do not support context menu. But you can use another technique to show a context menu:

    <telerik:RadMap x:Name="RadMap1" 
            <telerik:OpenStreetMapProvider />
            <ContextMenu Name="contextMenu">
        <telerik:InformationLayer x:Name="InformationLayer" />

    private Location menuLocation = Location.Empty;
    private void MenuItemClicked(object sender, RoutedEventArgs e)
        if (!this.menuLocation.IsEmpty)
            IEnumerable<object> list = this.InformationLayer.GetItemsInLocation(this.menuLocation);
            foreach (object item in list)
                MapShape shape = item as MapShape;
                if (shape != null)
                    // Do your things here
    private void RadMapContextMenuOpening(object sender, ContextMenuEventArgs e)
        this.menuLocation = Location.GetCoordinates(this.RadMap1, Mouse.GetPosition(this.RadMap1));
        bool close = true;
        IEnumerable<object> list = this.InformationLayer.GetItemsInLocation(this.menuLocation);
        foreach (object item in list)
            MapShape shape = item as MapShape;
            if (shape != null)
                close = false;
        if (!close)
        e.Handled = close;
    private void SetupContextMenuItems(ContextMenu menu)
        MenuItem baseItem = new MenuItem();
        baseItem.Width = 200;
        baseItem.Header = "Select Action";
        baseItem.Background = Brushes.Blue;
        baseItem.Foreground = Brushes.White;
        baseItem.FontWeight = FontWeights.Bold;
        baseItem.Click += new RoutedEventHandler(this.MenuItemClicked);
        MenuItem hidepolygonItem = new MenuItem();
        hidepolygonItem.Width = 200;
        hidepolygonItem.Header = "Hide Polyline";

    Andrey Murzov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top