mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Added MapItem.Location and LocationMemberPath
This commit is contained in:
parent
22fc5085de
commit
0d7387059b
|
|
@ -7,13 +7,45 @@ using System;
|
||||||
using Windows.Foundation;
|
using Windows.Foundation;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
|
using Windows.UI.Xaml.Data;
|
||||||
#else
|
#else
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace MapControl
|
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>
|
/// <summary>
|
||||||
/// Manages a collection of selectable items on a Map.
|
/// Manages a collection of selectable items on a Map.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -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)
|
protected double GetLongitudeOffset(Location location)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,28 @@
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
#if WINDOWS_UWP
|
#if WINDOWS_UWP
|
||||||
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
#else
|
#else
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pushpin at a geographic location specified by the MapPanel.Location attached property.
|
/// Pushpin at a geographic location specified by the Location property.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Pushpin : ContentControl
|
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()
|
public Pushpin()
|
||||||
{
|
{
|
||||||
DefaultStyleKey = typeof(Pushpin);
|
DefaultStyleKey = typeof(Pushpin);
|
||||||
|
|
@ -24,8 +34,8 @@ namespace MapControl
|
||||||
|
|
||||||
public Location Location
|
public Location Location
|
||||||
{
|
{
|
||||||
get { return MapPanel.GetLocation(this); }
|
get { return (Location)GetValue(LocationProperty); }
|
||||||
set { MapPanel.SetLocation(this, value); }
|
set { SetValue(LocationProperty, value); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,11 @@ using Windows.UI.Xaml.Input;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
/// <summary>
|
public partial class MapItem
|
||||||
/// Container class for an item in a MapItemsControl.
|
|
||||||
/// </summary>
|
|
||||||
public class MapItem : ListBoxItem
|
|
||||||
{
|
{
|
||||||
public MapItem()
|
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register(
|
||||||
{
|
nameof(Location), typeof(Location), typeof(MapItem),
|
||||||
DefaultStyleKey = typeof(MapItem);
|
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((FrameworkElement)o, (Location)e.NewValue)));
|
||||||
|
|
||||||
MapPanel.InitMapElement(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPointerPressed(PointerRoutedEventArgs e)
|
protected override void OnPointerPressed(PointerRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public partial class MapPath : Path
|
public partial class MapPath : Path
|
||||||
{
|
{
|
||||||
#region Method used only by derived classes MapPolyline and MapPolygon
|
#region Methods used only by derived classes MapPolyline and MapPolygon
|
||||||
|
|
||||||
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,9 @@ using System.Windows.Media;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
/// <summary>
|
public partial class MapItem
|
||||||
/// Container class for an item in a MapItemsControl.
|
|
||||||
/// </summary>
|
|
||||||
public class MapItem : ListBoxItem
|
|
||||||
{
|
{
|
||||||
public MapItem()
|
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(MapItem));
|
||||||
{
|
|
||||||
DefaultStyleKey = typeof(MapItem);
|
|
||||||
|
|
||||||
MapPanel.InitMapElement(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace MapControl
|
||||||
get { return Data; }
|
get { return Data; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Method used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
|
#region Methods used only by derived classes MapPolyline, MapPolygon and MapMultiPolygon
|
||||||
|
|
||||||
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
protected void DataCollectionPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
using MapControl;
|
|
||||||
using Windows.UI.Xaml;
|
|
||||||
using Windows.UI.Xaml.Data;
|
|
||||||
|
|
||||||
namespace UniversalApp
|
|
||||||
{
|
|
||||||
public class BindingHelper
|
|
||||||
{
|
|
||||||
public static readonly DependencyProperty LocationPathProperty = DependencyProperty.RegisterAttached(
|
|
||||||
"LocationPath", typeof(string), typeof(BindingHelper),
|
|
||||||
new PropertyMetadata(null, LocationPathPropertyChanged));
|
|
||||||
|
|
||||||
public static string GetLocationPath(DependencyObject obj)
|
|
||||||
{
|
|
||||||
return (string)obj.GetValue(LocationPathProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetLocationPath(DependencyObject obj, string value)
|
|
||||||
{
|
|
||||||
obj.SetValue(LocationPathProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void LocationPathPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
var propertyPath = e.NewValue as string;
|
|
||||||
|
|
||||||
if (propertyPath != null)
|
|
||||||
{
|
|
||||||
BindingOperations.SetBinding(
|
|
||||||
obj,
|
|
||||||
MapPanel.LocationProperty,
|
|
||||||
new Binding { Path = new PropertyPath(propertyPath) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
<Style x:Key="PointItemStyle" TargetType="map:MapItem">
|
<Style x:Key="PointItemStyle" TargetType="map:MapItem">
|
||||||
<Setter Property="local:BindingHelper.LocationPath" Value="Location"/>
|
<Setter Property="LocationMemberPath" Value="Location"/>
|
||||||
<Setter Property="Foreground" Value="Black"/>
|
<Setter Property="Foreground" Value="Black"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
|
|
@ -76,7 +76,7 @@
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
<Style x:Key="PushpinItemStyle" TargetType="map:MapItem">
|
<Style x:Key="PushpinItemStyle" TargetType="map:MapItem">
|
||||||
<Setter Property="local:BindingHelper.LocationPath" Value="Location"/>
|
<Setter Property="LocationMemberPath" Value="Location"/>
|
||||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||||
<Setter Property="Foreground" Value="Black"/>
|
<Setter Property="Foreground" Value="Black"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,6 @@
|
||||||
<Compile Include="App.xaml.cs">
|
<Compile Include="App.xaml.cs">
|
||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="BindingHelper.cs" />
|
|
||||||
<Compile Include="MainPage.xaml.cs">
|
<Compile Include="MainPage.xaml.cs">
|
||||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
<Style x:Key="PointItemStyle" TargetType="map:MapItem">
|
<Style x:Key="PointItemStyle" TargetType="map:MapItem">
|
||||||
<EventSetter Event="TouchDown" Handler="MapItemTouchDown"/>
|
<EventSetter Event="TouchDown" Handler="MapItemTouchDown"/>
|
||||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
<Setter Property="Location" Value="{Binding Location}"/>
|
||||||
<Setter Property="Foreground" Value="Black"/>
|
<Setter Property="Foreground" Value="Black"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
|
|
@ -80,7 +80,7 @@
|
||||||
|
|
||||||
<Style x:Key="PushpinItemStyle" TargetType="map:MapItem">
|
<Style x:Key="PushpinItemStyle" TargetType="map:MapItem">
|
||||||
<EventSetter Event="TouchDown" Handler="MapItemTouchDown"/>
|
<EventSetter Event="TouchDown" Handler="MapItemTouchDown"/>
|
||||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
<Setter Property="Location" Value="{Binding Location}"/>
|
||||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||||
<Setter Property="Foreground" Value="Black"/>
|
<Setter Property="Foreground" Value="Black"/>
|
||||||
<Setter Property="Visibility">
|
<Setter Property="Visibility">
|
||||||
|
|
@ -123,7 +123,7 @@
|
||||||
<RowDefinition/>
|
<RowDefinition/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<map:Map x:Name="map" ZoomLevel="11" MaxZoomLevel="21"
|
<map:Map x:Name="map" ZoomLevel="11" MaxZoomLevel="21" MouseWheelZoomDelta="0.5"
|
||||||
Center="{Binding MapCenter}"
|
Center="{Binding MapCenter}"
|
||||||
MapLayer="{Binding MapLayers.CurrentMapLayer}"
|
MapLayer="{Binding MapLayers.CurrentMapLayer}"
|
||||||
MapProjection="{Binding SelectedValue, ElementName=projectionComboBox,
|
MapProjection="{Binding SelectedValue, ElementName=projectionComboBox,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue