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

ContextMenu for MapPathView

2 Answers 59 Views
Map
This is a migrated thread and some comments may be shown as answers.
Etienne
Top achievements
Rank 1
Etienne asked on 10 Oct 2014, 06:08 PM
Hi,

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

Here's what I have :

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

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

VisualizationCreatedEvent:
        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!

Etienne

2 Answers, 1 is accepted

Sort by
0
Etienne
Top achievements
Rank 1
answered on 13 Oct 2014, 03:38 PM
I found a workaround, I added InheritDataContext="False" to my RadContextMenu.

Etienne

P.S.: If anyone knows why the DataContext was wrong, i'm still interested to know the answer.
0
Petar Mladenov
Telerik team
answered on 14 Oct 2014, 08:23 AM
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.

Regards,
Petar Mladenov
Telerik
 

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.

 
Tags
Map
Asked by
Etienne
Top achievements
Rank 1
Answers by
Etienne
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or