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

69 lines
2.3 KiB
C#
Raw Normal View History

2018-11-13 21:35:48 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2021-01-13 21:19:27 +01:00
// © 2021 Clemens Fischer
2018-11-13 21:35:48 +01:00
// Licensed under the Microsoft Public License (Ms-PL)
using Windows.System;
2021-06-14 21:41:37 +02:00
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
#else
2018-11-14 17:53:37 +01:00
using Windows.UI.Xaml;
2018-11-13 21:35:48 +01:00
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
2021-06-14 21:41:37 +02:00
#endif
2018-11-13 21:35:48 +01:00
namespace MapControl
{
public partial class MapItem
2018-11-13 21:35:48 +01:00
{
2021-01-13 00:08:55 +01:00
public static readonly DependencyProperty AutoCollapseProperty = DependencyProperty.Register(
nameof(AutoCollapse), typeof(bool), typeof(MapItem),
2021-01-16 18:32:31 +01:00
new PropertyMetadata(false, (o, e) => MapPanel.SetAutoCollapse((MapItem)o, (bool)e.NewValue)));
2021-01-13 00:08:55 +01:00
public static readonly DependencyProperty LocationProperty = DependencyProperty.Register(
nameof(Location), typeof(Location), typeof(MapItem),
2021-01-16 18:32:31 +01:00
new PropertyMetadata(null, (o, e) => MapPanel.SetLocation((MapItem)o, (Location)e.NewValue)));
2018-11-13 21:35:48 +01:00
2021-01-17 00:31:30 +01:00
public MapItem()
{
DefaultStyleKey = typeof(MapItem);
MapPanel.InitMapElement(this);
}
2018-11-13 21:35:48 +01:00
protected override void OnPointerPressed(PointerRoutedEventArgs e)
{
2018-11-14 17:53:37 +01:00
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked(
2018-11-13 21:35:48 +01:00
this, e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control), e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift));
}
2021-01-17 23:39:20 +01:00
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
var parentMap = MapPanel.GetParentMap(this);
if (parentMap != null)
{
this.ValidateProperty(BackgroundProperty, parentMap, nameof(MapBase.Background));
this.ValidateProperty(BorderBrushProperty, parentMap, nameof(MapBase.Foreground));
this.ValidateProperty(ForegroundProperty, parentMap, nameof(MapBase.Foreground));
}
}
2018-11-13 21:35:48 +01:00
}
public partial class MapItemsControl
{
2021-01-17 00:31:30 +01:00
public MapItemsControl()
{
DefaultStyleKey = typeof(MapItemsControl);
MapPanel.InitMapElement(this);
}
2018-11-14 17:53:37 +01:00
public new FrameworkElement ContainerFromItem(object item)
2018-11-13 21:35:48 +01:00
{
2018-11-14 17:53:37 +01:00
return (FrameworkElement)base.ContainerFromItem(item);
2018-11-13 21:35:48 +01:00
}
}
}