Win10 App - Holding & Releasing the map to manipulate an element on the interface

落花浮王杯 提交于 2019-12-11 20:28:29

问题


I working on an UWP (Win10) App with a simple location picker function. The user can drag the map on the wanted location. A basic Pushpin thats always in the center of the Map window acts as the location indicator. It works just like the free location pick in WhatsApp. To give the user feedback that he is moving the center pin, I want to raise the pin when the user is moving the map and lower it again on release.

Here the simple code to raise the pin (and manipulate the shadow):

private void MyMap_MapHolding(MapControl sender, MapInputEventArgs args)
    {
        iconSwitch = true;
        if(iconSwitch == true) {
            centerPin.Margin = new Thickness(0, 0, 0, 60);
            centerPinShadow.Opacity = 0.3;
            centerPinShadow.Width = 25;
     }

But this event doesn't seem to be affected on click & hold or tap & hold. Am I missing something?

FYI: I tried this out with the MyMap_MapTapped(...) method, and it worked just fine, but I need it when the map is dragged not just tapped.

Chees!


回答1:


I've tested and debugged, MapHolding event can't work by me either. For your purpose, CenterChangedLink event maybe helpful, I've tested it too.

Here is part of my sample code:

RandomAccessStreamReference mapIconStreamReference;
public Maptest()
{
    this.InitializeComponent();            
    myMap.Loaded += MyMap_Loaded;
    myMap.MapTapped += MyMap_MapTapped;
    myMap.MapHolding += MyMap_MapHolding;
    myMap.CenterChanged += MyMap_CenterChanged;
    mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/MapPin.png"));
}

private void MyMap_Loaded(object sender, RoutedEventArgs e)
{
    myMap.Center =
        new Geopoint(new BasicGeoposition()
        {
            //Geopoint for Seattle 
            Latitude = 47.604,
            Longitude = -122.329
        });
    myMap.ZoomLevel = 12;      

}

private void MyMap_MapTapped(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
{
    var tappedGeoPosition = args.Location.Position;
    string status = "MapTapped at \nLatitude:" + tappedGeoPosition.Latitude + "\nLongitude: " + tappedGeoPosition.Longitude;
    rootPage.NotifyUser( status, NotifyType.StatusMessage);
}

private void MyMap_MapHolding(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapInputEventArgs args)
{
    var holdingGeoPosition = args.Location.Position;
    string status = "MapHolding at \nLatitude:" + holdingGeoPosition.Latitude + "\nLongitude: " + holdingGeoPosition.Longitude;
    rootPage.NotifyUser(status, NotifyType.StatusMessage);
}

private void MyMap_CenterChanged(Windows.UI.Xaml.Controls.Maps.MapControl sender, object obj)
{
    MapIcon mapIcon = new MapIcon();
    mapIcon.Location = myMap.Center;
    mapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0);
    mapIcon.Title = "Here";
    mapIcon.Image = mapIconStreamReference;
    mapIcon.ZIndex = 0;
    myMap.MapElements.Add(mapIcon);
}

At first I thought, even when the MapHoling event can't work, the Tapped action before holding should handled by MapTapped event, but it is seems this action is ignored. So remember, if a user hold the Map but not move it, nothing will happen.



来源:https://stackoverflow.com/questions/33870330/win10-app-holding-releasing-the-map-to-manipulate-an-element-on-the-interfac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!