ContextMenu for MapPathView

3 posts, 0 answers
  1. Etienne
    Etienne avatar
    45 posts
    Member since:
    Sep 2014

    Posted 10 Oct 2014 Link to this post


    I'm trying to add a contextual menu to a MapPathView and I encountered some problems.

    Here's what I have :

                        <DataTemplate x:Key="ZoneTemplate" DataType="ZoneViewModel">
                                        <telerik:RadMenuItem Header="Remove" Command="{Binding DataContext.RemoveZoneCommand, Source={x:Reference parentControl}}" CommandParameter="{Binding}"/>

                    <telerik:VisualizationLayer UseDefaultPropertyAccessor="False" UseBitmapCache="False"
                                                ItemsSource="{Binding Path=CurrentZones}" ItemTemplate="{StaticResource ZoneTemplate}"
                                                MapShapeVisualizationCreated="OnVisualizationCreated" MapShapeVisualizationRemoved="OnVisualizationRemoved">
                            <telerik:MapShapeFill Fill="Blue" StrokeThickness="1" Stroke="Red" />

            private void OnVisualizationCreated(object sender, MapShapeOperationEventArgs e)
                if (e.Visualization != null)
                    var dataContext = e.Data.Wrapper.DataContext as ZoneViewModel;
                    if (dataContext != null)
                        var contextMenu = RadContextMenu.GetContextMenu(e.Data.Wrapper);
                        RadContextMenu.SetContextMenu(e.Visualization, contextMenu);
                        contextMenu.DataContext = dataContext;

    The contextual menu shows as expected, but the command parameter is not a ZoneViewModel as I expected, it's a PathData.
    Do you have any idea of what is the problem ?

    Thank you!

  2. Etienne
    Etienne avatar
    45 posts
    Member since:
    Sep 2014

    Posted 13 Oct 2014 Link to this post

    I found a workaround, I added InheritDataContext="False" to my RadContextMenu.


    P.S.: If anyone knows why the DataContext was wrong, i'm still interested to know the answer.
  3. DevCraft R3 2016 release webinar banner
  4. Petar Mladenov
    Petar Mladenov avatar
    2882 posts

    Posted 14 Oct 2014 Link to this post

    Hi Etienne,

    When using DataType you should not use x:Key on the DataTemplate and set it to ItemTemplate of the VisualizationLayer. In your scenario RadMap sets PathData object as a DataContext of the MapPathView.

    Petar Mladenov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top