ParentMap property initialization

This commit is contained in:
ClemensF 2021-01-17 00:31:30 +01:00
parent 6a9b622793
commit 207565feba
12 changed files with 86 additions and 47 deletions

View file

@ -15,6 +15,11 @@ namespace MapControl
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(MapItem));
static MapItem()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem)));
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked(
@ -24,6 +29,11 @@ namespace MapControl
public partial class MapItemsControl
{
static MapItemsControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItemsControl), new FrameworkPropertyMetadata(typeof(MapItemsControl)));
}
public FrameworkElement ContainerFromItem(object item)
{
return (FrameworkElement)ItemContainerGenerator.ContainerFromItem(item);

View file

@ -26,19 +26,19 @@ namespace MapControl
public static readonly DependencyProperty ParentMapProperty = ParentMapPropertyKey.DependencyProperty;
public static readonly DependencyProperty ViewPositionProperty = ViewPositionPropertyKey.DependencyProperty;
public MapPanel()
{
if (this is MapBase)
{
SetValue(ParentMapPropertyKey, this);
}
}
public static MapBase GetParentMap(FrameworkElement element)
{
return (MapBase)element.GetValue(ParentMapProperty);
}
public static void InitMapElement(FrameworkElement element)
{
if (element is MapBase)
{
element.SetValue(ParentMapPropertyKey, element);
}
}
private static void SetViewPosition(FrameworkElement element, Point? viewPosition)
{
element.SetValue(ViewPositionPropertyKey, viewPosition);

42
MapControl/WPF/Pushpin.cs Normal file
View file

@ -0,0 +1,42 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2021 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;
using System.Windows.Controls;
namespace MapControl
{
/// <summary>
/// Pushpin at a geographic location specified by the Location property.
/// </summary>
public class Pushpin : ContentControl
{
public static readonly DependencyProperty AutoCollapseProperty = MapPanel.AutoCollapseProperty.AddOwner(typeof(Pushpin));
public static readonly DependencyProperty LocationProperty = MapPanel.LocationProperty.AddOwner(typeof(Pushpin));
static Pushpin()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Pushpin), new FrameworkPropertyMetadata(typeof(Pushpin)));
}
/// <summary>
/// Gets/sets MapPanel.AutoCollapse.
/// </summary>
public bool AutoCollapse
{
get { return (bool)GetValue(AutoCollapseProperty); }
set { SetValue(AutoCollapseProperty, value); }
}
/// <summary>
/// Gets/sets MapPanel.Location.
/// </summary>
public Location Location
{
get { return (Location)GetValue(LocationProperty); }
set { SetValue(LocationProperty, value); }
}
}
}