2025-03-19 11:14:13 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using Windows.System;
|
2024-05-22 11:25:32 +02:00
|
|
|
|
#if UWP
|
2023-01-19 17:16:02 +01:00
|
|
|
|
using Windows.UI.Xaml;
|
2025-03-19 11:14:13 +01:00
|
|
|
|
using Windows.UI.Xaml.Controls;
|
2024-05-26 21:25:36 +02:00
|
|
|
|
using Windows.UI.Xaml.Data;
|
2023-01-19 17:16:02 +01:00
|
|
|
|
using Windows.UI.Xaml.Input;
|
2024-05-22 11:25:32 +02:00
|
|
|
|
#else
|
|
|
|
|
|
using Microsoft.UI.Xaml;
|
2025-03-19 11:14:13 +01:00
|
|
|
|
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;
|
2023-01-19 17:16:02 +01:00
|
|
|
|
#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));
|
2023-01-19 17:16:02 +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<MapItem, Location>(nameof(Location), null,
|
2024-05-25 15:55:31 +02:00
|
|
|
|
(item, oldValue, newValue) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
MapPanel.SetLocation(item, newValue);
|
|
|
|
|
|
item.UpdateMapTransform(newValue);
|
|
|
|
|
|
});
|
2023-01-19 17:16:02 +01:00
|
|
|
|
|
2025-03-19 11:14:13 +01:00
|
|
|
|
// Used to detect pointer movement between PointerPressed and
|
|
|
|
|
|
// PointerReleased in order to possibly cancel item selection.
|
|
|
|
|
|
//
|
|
|
|
|
|
private const float pointerMovementThreshold = 2f;
|
|
|
|
|
|
private Windows.Foundation.Point pointerPressedPosition;
|
|
|
|
|
|
|
2023-01-19 17:16:02 +01:00
|
|
|
|
public MapItem()
|
|
|
|
|
|
{
|
|
|
|
|
|
DefaultStyleKey = typeof(MapItem);
|
|
|
|
|
|
MapPanel.InitMapElement(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-19 11:14:13 +01:00
|
|
|
|
protected override void OnPointerPressed(PointerRoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
pointerPressedPosition = e.GetCurrentPoint(null).Position;
|
2025-03-19 15:27:27 +01:00
|
|
|
|
|
|
|
|
|
|
base.OnPointerPressed(e);
|
|
|
|
|
|
|
|
|
|
|
|
// Unsetting e.Handled enables PointerPressed event handlers
|
|
|
|
|
|
// and PointerPressed handling in class Map.
|
|
|
|
|
|
//
|
|
|
|
|
|
e.Handled = false;
|
2025-03-19 11:14:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-18 08:44:08 +01:00
|
|
|
|
protected override void OnPointerReleased(PointerRoutedEventArgs e)
|
2023-01-19 17:16:02 +01:00
|
|
|
|
{
|
2025-03-19 11:14:13 +01:00
|
|
|
|
var p = e.GetCurrentPoint(null).Position;
|
|
|
|
|
|
|
|
|
|
|
|
if (Math.Abs(p.X - pointerPressedPosition.X) <= pointerMovementThreshold &&
|
|
|
|
|
|
Math.Abs(p.Y - pointerPressedPosition.Y) <= pointerMovementThreshold &&
|
|
|
|
|
|
ItemsControl.ItemsControlFromItemContainer(this) is MapItemsControl mapItemsControl)
|
2025-03-13 19:34:07 +01:00
|
|
|
|
{
|
2025-03-19 11:14:13 +01:00
|
|
|
|
if (mapItemsControl.SelectionMode == SelectionMode.Extended &&
|
|
|
|
|
|
e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift))
|
|
|
|
|
|
{
|
|
|
|
|
|
mapItemsControl.SelectItemsInRange(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnPointerReleased(e);
|
|
|
|
|
|
}
|
2025-03-12 19:23:05 +01:00
|
|
|
|
}
|
2025-03-19 11:14:13 +01:00
|
|
|
|
|
2025-03-19 15:27:27 +01:00
|
|
|
|
// Unsetting e.Handled enables PointerReleased event handlers.
|
|
|
|
|
|
//
|
|
|
|
|
|
e.Handled = false;
|
2025-03-12 19:23:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-19 17:16:02 +01:00
|
|
|
|
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
|
|
|
|
}
|
2023-01-19 17:16:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|