Unable to capture PointerMoved and PointerPressed events in UWP MapControl
I am developing a UWP application for Windows 10 and am having trouble capturing the PointerMoved and PointerPressed events on a MapControl. I have tried adding the event handlers both in the XAML code and in the code-behind, but the events are not firing. The MapTapped and DoubleTapped events work correctly.
I have tried setting the IsHitTestVisible property of the MapControl to true, but I still cannot capture the events. I have also tried adding event handlers for the same events on the main container of the page, but they do not work either.
Interestingly, if I press the left mouse button outside of the MapControl and then move the pointer inside the control area while still holding down the button, then the PointerMoved event is triggered. However, if I release the button, the event is no longer triggered.
I have been trying to solve this issue for several days and have already reviewed several posts on Stack Overflow, but none of the solutions have worked for me.
Here is the code I am using:
c#:
namespace keypress
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void MapControl1_PointerMoved(object sender, PointerRoutedEventArgs e)
{
// Get the pointer position on the map
var pointerPosition = e.GetCurrentPoint(MapControl1);
var position = new Windows.Foundation.Point(pointerPosition.Position.X, pointerPosition.Position.Y);
// Convert the pointer position to a geographic position
MapControl1.GetLocationFromOffset(position, out Geopoint geographicPosition);
// Update the content of the TextBlock with the geographic coordinates
pepe.Text = $"Latitude: {geographicPosition.Position.Latitude}, Longitude: {geographicPosition.Position.Longitude}";
}
}
}
XAML:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:keypress"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Custom="using:Windows.UI.Xaml.Controls.Maps"
x:Class="keypress.MainPage"
mc:Ignorable="d"
Background="Red" >
<Grid>
<!-- MapControl with PointerMoved event handler and other properties set -->
<Custom:MapControl x:Name="MapControl1" PointerMoved="MapControl1_PointerMoved" IsTapEnabled="false" IsTabStop="true" MapServiceToken="YOUR_MAPSERVICE_TOKEN_HERE" IsHitTestVisible="true" HorizontalAlignment="Left" Height="348" Margin="22,59,0,0" VerticalAlignment="Top" Width="571"/>
<!-- TextBlock to display geographic coordinates -->
<TextBlock x:Name="pepe" HorizontalAlignment="Left" Height="73" Margin="18,13,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="204"/>
</Grid>
</Page>`
Does anyone know why I cannot capture these events on the MapControl? Is there any solution or workaround for this issue? Thank you in advance for your help.