This project has moved. For the latest updates, please go here.

About dragging the pin to change the position of the pin on the map

Mar 20 at 2:45 AM
Edited Mar 20 at 2:46 AM
XAML:
    <Style x:Key="PointItemStyle" TargetType="Maps:MapItem">
        <Setter Property="helper:BindingHelper.LocationPath" Value="Location"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Maps:MapItem">
                    <Canvas PointerMoved="Pushpin_PointerMoved">
                        <Grid>
                            <Path Fill="GreenYellow" Stroke="Green" StrokeThickness="2">
                                <Path.Data>
                                    <EllipseGeometry RadiusX="8" RadiusY="8"/>
                                </Path.Data>
                            </Path>
                            <Rectangle x:Name="labelBackground" Fill="White" Opacity="0.7"/>
                            <TextBlock Margin="2,0,2,0" Text="{Binding DisplayName}"/>
                        </Grid>
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    private void Pushpin_PointerMoved(object sender, PointerRoutedEventArgs e)
    {
        var pointerPosition = e.GetCurrentPoint(PlanningMapControl);
        var point = e.GetCurrentPoint((UIElement)sender);
        if (point.Properties.IsLeftButtonPressed)
        {
            Location location = PlanningMapControl.ViewportPointToLocation(pointerPosition.Position);
                PushpinViewModels.Pushpins[index].Location = location;}}
Why is this wrong? Is there any good way? thank you very much!
Coordinator
Mar 20 at 6:07 PM
Edited Mar 20 at 6:08 PM
The PointerMoved event should not be handled on an element inside the item container's visual tree, because the item container is itself moving around (to the item's Location). Handle the event on an element outside of the MapItemsControl.
Mar 21 at 3:10 AM
Very grateful to ClemensF, I am a beginner, the following is the call to the map of XAML:
    <Maps:Map x:Name="PlanningMapControl" TileLayer="{Binding [OpenStreetMap], Source={StaticResource TileLayers}}" 
              MinZoomLevel="2" ZoomLevel="5" ManipulationMode="All" Loaded="PlanningMapControl_Loaded" Tapped="PlanningMapControl_MapTapped" >
        <Maps:MapPanel>


            <Maps:MapItemsControl ItemsSource="{x:Bind PushpinViewModels.Pushpins}" ItemContainerStyle="{StaticResource PointItemStyle}"/>


        </Maps:MapPanel>

    </Maps:Map>
How should I modify it? Can I provide some code? thank you very much!
Coordinator
Mar 22 at 7:35 PM
Sorry, this is not the right place for a beginner's education. Please do your own research. When you have a specific problem related to the map control, we'll be pleased to help.