XAML-Map-Control/MapControl/WinUI/MapContentControl.WinUI.cs

83 lines
2.8 KiB
C#
Raw Normal View History

2021-01-17 21:39:42 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2022-01-14 20:22:56 +01:00
// © 2022 Clemens Fischer
2021-01-17 21:39:42 +01:00
// Licensed under the Microsoft Public License (Ms-PL)
2021-06-14 21:41:37 +02:00
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
#else
2021-01-17 21:39:42 +01:00
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
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
{
public static readonly DependencyProperty AutoCollapseProperty = DependencyProperty.Register(
nameof(AutoCollapse), typeof(bool), typeof(MapContentControl),
new PropertyMetadata(false, (o, e) => MapPanel.SetAutoCollapse((MapContentControl)o, (bool)e.NewValue)));
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register(
nameof(Location), typeof(Location), typeof(MapContentControl),
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((MapContentControl)o, (Location)e.NewValue)));
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
{
2021-12-01 20:15:48 +01:00
// If this.Background is not explicitly set, bind it to parentMap.Background
this.SetBindingOnUnsetProperty(BackgroundProperty, parentMap, Panel.BackgroundProperty, nameof(Background));
// If this.Foreground is not explicitly set, bind it to parentMap.Foreground
this.SetBindingOnUnsetProperty(ForegroundProperty, parentMap, MapBase.ForegroundProperty, nameof(Foreground));
// If this.BorderBrush is not explicitly set, bind it to parentMap.Foreground
this.SetBindingOnUnsetProperty(BorderBrushProperty, parentMap, MapBase.ForegroundProperty, nameof(Foreground));
2021-01-17 21:39:42 +01:00
}
}
}
/// <summary>
/// MapContentControl with a Pushpin Style.
/// </summary>
public class Pushpin : MapContentControl
{
public Pushpin()
{
DefaultStyleKey = typeof(Pushpin);
}
}
}