A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello,
The reason for repeated page loading is that every time you display the page, the Appearing method is executed. In the ViewModel, each Pin is cleared and reloaded, which causes the map to reload the ItemSource and re-render each time.
If your requirement is to reload all map markers when the page is displayed, this is unavoidable.
I noticed that in your LoadTurbinePins method, all the data is added to the TurbinePins each time it is run. Have you tried running this code multiple times and found that the TurbinePins contain duplicate data? This duplicate data will also cause the Map control to refresh due to changes in the Itemsource data.
Before updating data, it is recommended that you check whether the data already exists or has been deleted to avoid multiple loading problems.
foreach (var pin in turbinePins)
{
if(!TurbinePins.Contains(pin))
TurbinePins.Add(pin);
}
Well since MVVM pattern you are not supposed to use any code behind, how I am supposed, to navigate the current location of the map?
The Pin type supports MarkerClicked events. You can place it in a Xaml page and convert the Sender to the Pin class in the event. Please refer to the following code.
<maps:Pin MarkerClicked="Pin_MarkerClicked"/>
private void Pin_MarkerClicked(object sender, PinClickedEventArgs e)
{
var pin = sender as Pin;
map.MoveToRegion(MapSpan.FromCenterAndRadius(pin.Location, Distance.FromKilometers(2)));
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.