Added MapItem.Location and LocationMemberPath

This commit is contained in:
ClemensF 2021-01-11 22:35:17 +01:00
parent 22fc5085de
commit 0d7387059b
11 changed files with 59 additions and 68 deletions

View file

@ -7,13 +7,45 @@ using System;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
#else
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
#endif
namespace MapControl
{
/// <summary>
/// Container class for an item in a MapItemsControl.
/// </summary>
public partial class MapItem : ListBoxItem
{
public static readonly DependencyProperty LocationMemberPathProperty = DependencyProperty.Register(
nameof(LocationMemberPath), typeof(string), typeof(MapItem),
new PropertyMetadata(null, (o, e) => BindingOperations.SetBinding(
o, LocationProperty, new Binding { Path = new PropertyPath((string)e.NewValue) })));
public MapItem()
{
DefaultStyleKey = typeof(MapItem);
MapPanel.InitMapElement(this);
}
public Location Location
{
get { return (Location)GetValue(LocationProperty); }
set { SetValue(LocationProperty, value); }
}
public string LocationMemberPath
{
get { return (string)GetValue(LocationMemberPathProperty); }
set { SetValue(LocationMemberPathProperty, value); }
}
}
/// <summary>
/// Manages a collection of selectable items on a Map.
/// </summary>

View file

@ -83,7 +83,7 @@ namespace MapControl
}
}
#region Method used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
#region Methods used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
protected double GetLongitudeOffset(Location location)
{

View file

@ -3,18 +3,28 @@
// Licensed under the Microsoft Public License (Ms-PL)
#if WINDOWS_UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#else
using System.Windows;
using System.Windows.Controls;
#endif
namespace MapControl
{
/// <summary>
/// Pushpin at a geographic location specified by the MapPanel.Location attached property.
/// Pushpin at a geographic location specified by the Location property.
/// </summary>
public class Pushpin : ContentControl
{
public static readonly DependencyProperty LocationProperty =
#if WINDOWS_UWP
DependencyProperty.Register(
nameof(Location), typeof(Location), typeof(Pushpin),
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((FrameworkElement)o, (Location)e.NewValue)));
#else
MapPanel.LocationProperty.AddOwner(typeof(Pushpin));
#endif
public Pushpin()
{
DefaultStyleKey = typeof(Pushpin);
@ -24,8 +34,8 @@ namespace MapControl
public Location Location
{
get { return MapPanel.GetLocation(this); }
set { MapPanel.SetLocation(this, value); }
get { return (Location)GetValue(LocationProperty); }
set { SetValue(LocationProperty, value); }
}
}
}