MapPolygon and RadContextMenu

2 posts, 0 answers
  1. Michael
    Michael avatar
    18 posts
    Member since:
    Jul 2012

    Posted 19 Jul 2013 Link to this post

    Is it possible to put a RadContextMenu on a MapPolygon? I have tried and the menu does not show up on right-click.

    Thanks,
    Mike
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 24 Jul 2013 Link to this post

    Hi Michael,

    In fact the map shape is not a visual object. It is a data object. So, you can use the RadContextMenu only with visual representation of the MapPolygon. You can get it using the InformationLayer.ItemContainerGenerator.
    The sample code is below.
    <Window x:Class="ContextMenu.MainWindow"
            Title="MainWindow" Height="600" Width="800">
        <Grid>
            <telerik:RadMap x:Name="radMap"
                            Center="40,-100"
                            ZoomLevel="7">
                <telerik:RadMap.Providers>
                    <telerik:OpenStreetMapProvider />
                </telerik:RadMap.Providers>
                <telerik:InformationLayer Name="informationLayer">
                    <telerik:MapPolygon x:Name="polygon"
                                        Fill="Blue"
                                        Stroke="Yellow"
                                        StrokeThickness="1"
                                        Points="40,-100 42,-101.5 42,-102 40,-101 40,-100">
                        <telerik:RadContextMenu.ContextMenu>
                            <telerik:RadContextMenu>
                                <telerik:RadMenuItem Header="Menu Item 1" />
                                <telerik:RadMenuItem Header="Menu Item 2" />
                                <telerik:RadMenuItem Header="Menu Item 3" />
                            </telerik:RadContextMenu>
                        </telerik:RadContextMenu.ContextMenu>
                    </telerik:MapPolygon>
                </telerik:InformationLayer>
            </telerik:RadMap>
        </Grid>
    </Window>
    using System;
    using System.Windows;
    using System.Windows.Controls.Primitives;
    using Telerik.Windows.Controls;
     
    namespace ContextMenu
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
     
                this.informationLayer.ItemContainerGenerator.StatusChanged += this.ItemContainerGenerator_StatusChanged;
            }
     
            private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
            {
                if (this.informationLayer.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated)
                {
                    FrameworkElement container = this.informationLayer.ItemContainerGenerator.ContainerFromItem(this.polygon) as FrameworkElement;
                    if (container != null)
                    {
                        this.informationLayer.ItemContainerGenerator.StatusChanged -= this.ItemContainerGenerator_StatusChanged;
                        var menu = RadContextMenu.GetContextMenu(this.polygon);
                        RadContextMenu.SetContextMenu(container, menu);
                    }
                }
            }
        }
    }

    Regards,
    Andrey Murzov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top