Added DependencyPropertyHelper

This commit is contained in:
ClemensFischer 2024-05-20 23:24:34 +02:00
parent 422f1dce0d
commit 3706709cfc
22 changed files with 967 additions and 1879 deletions

View file

@ -3,15 +3,11 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;
using System.Windows.Controls;
namespace MapControl
{
public partial class MapBase
{
public static readonly DependencyProperty ForegroundProperty =
Control.ForegroundProperty.AddOwner(typeof(MapBase));
public static readonly DependencyProperty CenterProperty = DependencyProperty.Register(
nameof(Center), typeof(Location), typeof(MapBase), new FrameworkPropertyMetadata(
new Location(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,

View file

@ -2,35 +2,20 @@
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
namespace MapControl
{
public partial class MapPanel
{
public static readonly DependencyProperty LocationProperty = DependencyProperty.RegisterAttached(
"Location", typeof(Location), typeof(MapPanel),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsParentArrange));
public static readonly DependencyProperty BoundingBoxProperty = DependencyProperty.RegisterAttached(
"BoundingBox", typeof(BoundingBox), typeof(MapPanel),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsParentArrange));
private static readonly DependencyPropertyKey ParentMapPropertyKey = DependencyProperty.RegisterAttachedReadOnly(
"ParentMap", typeof(MapBase), typeof(MapPanel),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits, ParentMapPropertyChanged));
private static readonly DependencyPropertyKey ViewPositionPropertyKey = DependencyProperty.RegisterAttachedReadOnly(
"ViewPosition", typeof(Point?), typeof(MapPanel), new PropertyMetadata());
public static readonly DependencyProperty ParentMapProperty = ParentMapPropertyKey.DependencyProperty;
public static readonly DependencyProperty ViewPositionProperty = ViewPositionPropertyKey.DependencyProperty;
public MapPanel()
{
if (this is MapBase)
{
SetValue(ParentMapPropertyKey, this);
SetValue(ParentMapProperty, this);
}
}
@ -39,14 +24,17 @@ namespace MapControl
return (MapBase)element.GetValue(ParentMapProperty);
}
/// <summary>
/// Sets the attached ViewPosition property of an element. The method is called during
/// ArrangeOverride and may be overridden to modify the actual view position value.
/// An overridden method should call this method to set the attached property.
/// </summary>
protected virtual void SetViewPosition(FrameworkElement element, ref Point? position)
public static void SetRenderTransform(FrameworkElement element, Transform transform, double originX = 0d, double originY = 0d)
{
element.SetValue(ViewPositionPropertyKey, position);
element.RenderTransform = transform;
element.RenderTransformOrigin = new Point(originX, originY);
}
private IEnumerable<FrameworkElement> ChildElements => Children.OfType<FrameworkElement>();
private static void SetVisible(FrameworkElement element, bool visible)
{
element.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
}
}
}

View file

@ -3,10 +3,11 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System;
#if UWP
#if AVALONIA
using Avalonia.Threading;
#elif UWP
using Windows.UI.Xaml;
#else
using System.Windows;
using System.Windows.Threading;
#endif
@ -14,14 +15,9 @@ namespace MapControl
{
internal static class Timer
{
public static DispatcherTimer CreateTimer(this DependencyObject obj, TimeSpan interval)
public static DispatcherTimer CreateTimer(this object _, TimeSpan interval)
{
var timer = new DispatcherTimer
{
Interval = interval
};
return timer;
return new DispatcherTimer { Interval = interval };
}
public static void Run(this DispatcherTimer timer, bool restart = false)