This is a migrated thread and some comments may be shown as answers.

MapPolygon and RadContextMenu

1 Answer 57 Views
Map
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 19 Jul 2013, 09:27 PM
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

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 24 Jul 2013, 02:15 PM
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 >>
Tags
Map
Asked by
Michael
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or