How to launch popup above map pushpin

Apptacular Apps 386 Reputation points
2020-06-26T16:22:19.567+00:00

Everytime I click a pushpin in my MapControl the Popup always appears in the top-left corner of the MapControl. How can this be changed so that it appears above the pushpin itself?

MainPage.xaml

<Page  
    x:Class="MyApp.PageMap"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:local="using:MyApp"  
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
    xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"  
    mc:Ignorable="d">  
  
    <Grid x:Name="GridMap">  
        <Grid.RowDefinitions>  
            <RowDefinition Height="*"/>  
            <RowDefinition Height="Auto"/>  
        </Grid.RowDefinitions>  
  
        <Maps:MapControl  
            Grid.Row="0"  
            x:Name="MyMapControl"    
            ZoomLevel="8"  
            MapElementClick="MyMapControl_MapElementClick">  
  
            <Popup x:Name="PushpinPopup" IsLightDismissEnabled="True">  
                <Grid Background="Black">  
                    <TextBlock Text="Hello World"/>  
                </Grid>  
            </Popup>  
        </Maps:MapControl>  
    </Grid>  
</Page>  

10851-map-popup.png

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Daniele 1,996 Reputation points
    2020-06-27T07:52:17.577+00:00

    Try with this

    private void MyMapControl_MapElementClick(MapControl mapControl, MapElementClickEventArgs args)
    {
        Point point = args.Position;
        PushpinPopup.HorizontalOffset = point.X;
        PushpinPopup.VerticalOffset = point.Y;
        PushpinPopup.IsOpen = true;
    }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.