2021-01-17 21:39:42 +01:00
|
|
|
|
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
2024-02-03 21:01:53 +01:00
|
|
|
|
// Copyright © 2024 Clemens Fischer
|
2021-01-17 21:39:42 +01:00
|
|
|
|
// Licensed under the Microsoft Public License (Ms-PL)
|
|
|
|
|
|
|
2024-05-22 11:25:32 +02:00
|
|
|
|
#if UWP
|
2021-01-17 21:39:42 +01:00
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
2024-05-26 21:25:36 +02:00
|
|
|
|
using Windows.UI.Xaml.Data;
|
2024-05-22 11:25:32 +02:00
|
|
|
|
#else
|
|
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
2024-05-26 21:25:36 +02:00
|
|
|
|
using Microsoft.UI.Xaml.Data;
|
2021-06-14 21:41:37 +02:00
|
|
|
|
#endif
|
2021-01-17 21:39:42 +01:00
|
|
|
|
|
|
|
|
|
|
namespace MapControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ContentControl placed on a MapPanel at a geographic location specified by the Location property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class MapContentControl : ContentControl
|
|
|
|
|
|
{
|
2024-05-23 18:08:14 +02:00
|
|
|
|
public static readonly DependencyProperty AutoCollapseProperty =
|
2024-05-23 18:22:52 +02:00
|
|
|
|
DependencyPropertyHelper.Register<MapContentControl, bool>(nameof(AutoCollapse), false,
|
2024-05-23 18:08:14 +02:00
|
|
|
|
(control, oldValue, newValue) => MapPanel.SetAutoCollapse(control, newValue));
|
2021-01-17 21:39:42 +01:00
|
|
|
|
|
2024-05-23 18:08:14 +02:00
|
|
|
|
public static readonly DependencyProperty LocationProperty =
|
2024-05-23 18:22:52 +02:00
|
|
|
|
DependencyPropertyHelper.Register<MapContentControl, Location>(nameof(Location), null,
|
2024-05-23 18:08:14 +02:00
|
|
|
|
(control, oldValue, newValue) => MapPanel.SetLocation(control, newValue));
|
2021-01-17 21:39:42 +01:00
|
|
|
|
|
|
|
|
|
|
public MapContentControl()
|
|
|
|
|
|
{
|
|
|
|
|
|
DefaultStyleKey = typeof(MapContentControl);
|
|
|
|
|
|
MapPanel.InitMapElement(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets/sets MapPanel.AutoCollapse.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool AutoCollapse
|
|
|
|
|
|
{
|
2022-08-06 10:40:59 +02:00
|
|
|
|
get => (bool)GetValue(AutoCollapseProperty);
|
|
|
|
|
|
set => SetValue(AutoCollapseProperty, value);
|
2021-01-17 21:39:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets/sets MapPanel.Location.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Location Location
|
|
|
|
|
|
{
|
2022-08-06 10:40:59 +02:00
|
|
|
|
get => (Location)GetValue(LocationProperty);
|
|
|
|
|
|
set => SetValue(LocationProperty, value);
|
2021-01-17 21:39:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnApplyTemplate()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnApplyTemplate();
|
|
|
|
|
|
|
2021-01-17 23:39:20 +01:00
|
|
|
|
var parentMap = MapPanel.GetParentMap(this);
|
2021-01-17 21:39:42 +01:00
|
|
|
|
|
2021-01-17 23:39:20 +01:00
|
|
|
|
if (parentMap != null)
|
2021-01-17 21:39:42 +01:00
|
|
|
|
{
|
2024-05-25 15:55:31 +02:00
|
|
|
|
// Workaround for missing RelativeSource AncestorType=MapBase Bindings in default Style.
|
|
|
|
|
|
//
|
2024-05-24 18:24:44 +02:00
|
|
|
|
if (Background == null)
|
|
|
|
|
|
{
|
2024-05-26 21:25:36 +02:00
|
|
|
|
SetBinding(BackgroundProperty,
|
|
|
|
|
|
new Binding { Source = parentMap, Path = new PropertyPath(nameof(Background)) });
|
2024-05-24 18:24:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (Foreground == null)
|
|
|
|
|
|
{
|
2024-05-26 21:25:36 +02:00
|
|
|
|
SetBinding(ForegroundProperty,
|
|
|
|
|
|
new Binding { Source = parentMap, Path = new PropertyPath(nameof(Foreground)) });
|
2024-05-24 18:24:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
if (BorderBrush == null)
|
|
|
|
|
|
{
|
2024-05-26 21:25:36 +02:00
|
|
|
|
SetBinding(BorderBrushProperty,
|
|
|
|
|
|
new Binding { Source = parentMap, Path = new PropertyPath(nameof(Foreground)) });
|
2024-05-24 18:24:44 +02:00
|
|
|
|
}
|
2021-01-17 21:39:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// MapContentControl with a Pushpin Style.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Pushpin : MapContentControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public Pushpin()
|
|
|
|
|
|
{
|
|
|
|
|
|
DefaultStyleKey = typeof(Pushpin);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|