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

75 lines
2.5 KiB
C#
Raw Normal View History

// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2025-01-01 18:57:55 +01:00
// Copyright © Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.System;
2024-05-22 11:25:32 +02:00
#if UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
2024-05-26 21:25:36 +02:00
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
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;
2024-05-22 11:25:32 +02:00
using Microsoft.UI.Xaml.Input;
#endif
namespace MapControl
{
public partial class MapItem
{
2024-05-23 18:08:14 +02:00
public static readonly DependencyProperty AutoCollapseProperty =
2024-05-23 18:22:52 +02:00
DependencyPropertyHelper.Register<MapItem, bool>(nameof(AutoCollapse), false,
2024-05-23 18:08:14 +02:00
(item, oldValue, newValue) => MapPanel.SetAutoCollapse(item, newValue));
2024-05-23 18:08:14 +02:00
public static readonly DependencyProperty LocationProperty =
2024-05-23 18:22:52 +02:00
DependencyPropertyHelper.Register<MapItem, Location>(nameof(Location), null,
2024-05-25 15:55:31 +02:00
(item, oldValue, newValue) =>
{
MapPanel.SetLocation(item, newValue);
item.UpdateMapTransform(newValue);
});
public MapItem()
{
DefaultStyleKey = typeof(MapItem);
MapPanel.InitMapElement(this);
}
protected override void OnPointerPressed(PointerRoutedEventArgs e)
{
2024-05-29 16:29:13 +02:00
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?
.OnItemClicked(this, e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control));
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
var parentMap = MapPanel.GetParentMap(this);
if (parentMap != null)
{
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
}
}
}
}
}