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

74 lines
2.6 KiB
C#
Raw Normal View History

2018-11-13 21:35:48 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2022-01-14 20:22:56 +01:00
// © 2022 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)
{
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 23:39:20 +01:00
}
}
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
}
}
}