From 17fdde66d94155fc62a034fa6658995bef6fd6e5 Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Tue, 22 Mar 2016 13:02:25 -0700 Subject: Initial import --- Xamarin.Forms.Maps.UWP/PushPin.cs | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Xamarin.Forms.Maps.UWP/PushPin.cs (limited to 'Xamarin.Forms.Maps.UWP/PushPin.cs') diff --git a/Xamarin.Forms.Maps.UWP/PushPin.cs b/Xamarin.Forms.Maps.UWP/PushPin.cs new file mode 100644 index 00000000..2eaaa658 --- /dev/null +++ b/Xamarin.Forms.Maps.UWP/PushPin.cs @@ -0,0 +1,70 @@ +using System; +using System.ComponentModel; +using Windows.Devices.Geolocation; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Maps; +using Windows.UI.Xaml.Input; + +#if WINDOWS_UWP + +namespace Xamarin.Forms.Maps.UWP +#else + +namespace Xamarin.Forms.Maps.WinRT +#endif +{ + internal class PushPin : ContentControl + { + readonly Pin _pin; + + internal PushPin(Pin pin) + { + if (pin == null) + throw new ArgumentNullException(); + + ContentTemplate = Windows.UI.Xaml.Application.Current.Resources["pushPinTemplate"] as Windows.UI.Xaml.DataTemplate; + DataContext = Content = _pin = pin; + + UpdateLocation(); + + Loaded += PushPinLoaded; + Unloaded += PushPinUnloaded; + Tapped += PushPinTapped; + } + + void PushPinLoaded(object sender, RoutedEventArgs e) + { + _pin.PropertyChanged += PinPropertyChanged; + } + + void PushPinUnloaded(object sender, RoutedEventArgs e) + { + _pin.PropertyChanged -= PinPropertyChanged; + Tapped -= PushPinTapped; + } + + void PinPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == Pin.PositionProperty.PropertyName) + UpdateLocation(); + } + + void PushPinTapped(object sender, TappedRoutedEventArgs e) + { + _pin.SendTap(); + } + + void UpdateLocation() + { + var anchor = new Windows.Foundation.Point(0.65, 1); + var location = new Geopoint(new BasicGeoposition + { + Latitude = _pin.Position.Latitude, + Longitude = _pin.Position.Longitude + }); + MapControl.SetLocation(this, location); + MapControl.SetNormalizedAnchorPoint(this, anchor); + } + } +} \ No newline at end of file -- cgit v1.2.3