Use AddOwner for MapBase.Foreground

This commit is contained in:
ClemensFischer 2024-05-24 15:14:05 +02:00
parent 3c907c3345
commit 197f004eeb
10 changed files with 45 additions and 60 deletions

View file

@ -46,5 +46,12 @@ namespace MapControl
return property;
}
public static StyledProperty<TValue> AddOwner<TOwner, TValue>(
StyledProperty<TValue> property)
where TOwner : AvaloniaObject
{
return property.AddOwner<TOwner>();
}
}
}

View file

@ -6,6 +6,7 @@ global using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Media;
using Avalonia.Styling;
using System.Threading;
@ -15,6 +16,9 @@ namespace MapControl
{
public partial class MapBase
{
public static readonly StyledProperty<IBrush> ForegroundProperty =
DependencyPropertyHelper.AddOwner<MapBase, IBrush>(TextElement.ForegroundProperty);
public static readonly StyledProperty<Easing> AnimationEasingProperty =
DependencyPropertyHelper.Register<MapBase, Easing>(nameof(AnimationEasing), new QuadraticEaseOut());

View file

@ -17,6 +17,10 @@
<DefineConstants>AVALONIA</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\MapControl.snk" Link="MapControl.snk" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\*.cs" />
<Compile Remove="..\Shared\BindingHelper.cs" />
@ -33,10 +37,6 @@
<Compile Remove="..\Shared\ViewTransform.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\MapControl.snk" Link="MapControl.snk" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.10" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />

View file

@ -7,15 +7,12 @@ using System;
using System.Windows;
using System.Windows.Media;
#elif UWP
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#elif WINUI
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
#elif AVALONIA
using Avalonia.Media;
using Brush = Avalonia.Media.IBrush;
using DependencyProperty = Avalonia.AvaloniaProperty;
using UIElement = Avalonia.Controls.Control;
@ -40,9 +37,6 @@ namespace MapControl
{
public static TimeSpan ImageFadeDuration { get; set; } = TimeSpan.FromSeconds(0.1);
public static readonly DependencyProperty ForegroundProperty =
DependencyPropertyHelper.Register<MapBase, Brush>(nameof(Foreground), new SolidColorBrush(Colors.Black));
public static readonly DependencyProperty AnimationDurationProperty =
DependencyPropertyHelper.Register<MapBase, TimeSpan>(nameof(AnimationDuration), TimeSpan.FromSeconds(0.3));

View file

@ -73,24 +73,9 @@ namespace MapControl
return DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(defaultValue));
}
public static DependencyProperty AddOwner<TOwner>(
DependencyProperty property,
FrameworkPropertyMetadataOptions options = FrameworkPropertyMetadataOptions.None)
where TOwner : DependencyObject
{
FrameworkPropertyMetadata metadata = null;
if (options != FrameworkPropertyMetadataOptions.None)
{
metadata = new FrameworkPropertyMetadata(property.DefaultMetadata.DefaultValue, options);
}
return property.AddOwner(typeof(TOwner), metadata);
}
public static DependencyProperty AddOwner<TOwner, TValue>(
DependencyProperty property,
Action<TOwner, TValue, TValue> changed)
Action<TOwner, TValue, TValue> changed = null)
where TOwner : DependencyObject
{
FrameworkPropertyMetadata metadata = null;

View file

@ -3,12 +3,17 @@
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace MapControl
{
public partial class MapBase
{
public static readonly DependencyProperty ForegroundProperty =
DependencyPropertyHelper.AddOwner<MapBase, Brush>(TextElement.ForegroundProperty);
public static readonly DependencyProperty AnimationEasingFunctionProperty =
DependencyPropertyHelper.Register<MapBase, IEasingFunction>(nameof(AnimationEasingFunction),
new QuadraticEase { EasingMode = EasingMode.EaseOut });

View file

@ -13,10 +13,10 @@ namespace MapControl
public class MapContentControl : ContentControl
{
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.AddOwner<MapContentControl>(MapPanel.AutoCollapseProperty);
DependencyPropertyHelper.AddOwner<MapContentControl, bool>(MapPanel.AutoCollapseProperty);
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.AddOwner<MapContentControl>(MapPanel.LocationProperty);
DependencyPropertyHelper.AddOwner<MapContentControl, Location>(MapPanel.LocationProperty);
static MapContentControl()
{

View file

@ -11,7 +11,7 @@ namespace MapControl
public partial class MapItem
{
public static readonly DependencyProperty AutoCollapseProperty =
DependencyPropertyHelper.AddOwner<MapItem>(MapPanel.AutoCollapseProperty);
DependencyPropertyHelper.AddOwner<MapItem, bool>(MapPanel.AutoCollapseProperty);
public static readonly DependencyProperty LocationProperty =
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty,

View file

@ -13,64 +13,49 @@ namespace MapControl
public partial class MapOverlay
{
public static readonly DependencyProperty FontFamilyProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontFamilyProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
DependencyPropertyHelper.AddOwner<MapOverlay, FontFamily>(TextElement.FontFamilyProperty);
public static readonly DependencyProperty FontSizeProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontSizeProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
DependencyPropertyHelper.AddOwner<MapOverlay, double>(TextElement.FontSizeProperty);
public static readonly DependencyProperty FontStyleProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontStyleProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
DependencyPropertyHelper.AddOwner<MapOverlay, FontStyle>(TextElement.FontStyleProperty);
public static readonly DependencyProperty FontStretchProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontStretchProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
DependencyPropertyHelper.AddOwner<MapOverlay, FontStretch>(TextElement.FontStretchProperty);
public static readonly DependencyProperty FontWeightProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontWeightProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
DependencyPropertyHelper.AddOwner<MapOverlay, FontWeight>(TextElement.FontWeightProperty);
public static readonly DependencyProperty ForegroundProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.ForegroundProperty,
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
DependencyPropertyHelper.AddOwner<MapOverlay, Brush>(TextElement.ForegroundProperty);
public static readonly DependencyProperty StrokeProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, Brush>(Shape.StrokeProperty);
public static readonly DependencyProperty StrokeThicknessProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeThicknessProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, double>(Shape.StrokeThicknessProperty);
public static readonly DependencyProperty StrokeDashArrayProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashArrayProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, DoubleCollection>(Shape.StrokeDashArrayProperty);
public static readonly DependencyProperty StrokeDashOffsetProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashOffsetProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, double>(Shape.StrokeDashOffsetProperty);
public static readonly DependencyProperty StrokeDashCapProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashCapProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, PenLineCap>(Shape.StrokeDashCapProperty);
public static readonly DependencyProperty StrokeStartLineCapProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeStartLineCapProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, PenLineCap>(Shape.StrokeStartLineCapProperty);
public static readonly DependencyProperty StrokeEndLineCapProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeEndLineCapProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, PenLineCap>(Shape.StrokeEndLineCapProperty);
public static readonly DependencyProperty StrokeLineJoinProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeLineJoinProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, PenLineJoin>(Shape.StrokeLineJoinProperty);
public static readonly DependencyProperty StrokeMiterLimitProperty =
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeMiterLimitProperty,
FrameworkPropertyMetadataOptions.AffectsRender);
DependencyPropertyHelper.AddOwner<MapOverlay, double>(Shape.StrokeMiterLimitProperty);
protected override void OnInitialized(EventArgs e)
{

View file

@ -18,6 +18,10 @@ namespace MapControl
{
public partial class MapBase
{
public static readonly DependencyProperty ForegroundProperty =
DependencyPropertyHelper.Register<MapBase, Brush>(nameof(Foreground),
new SolidColorBrush(Colors.Black));
public static readonly DependencyProperty AnimationEasingFunctionProperty =
DependencyPropertyHelper.Register<MapBase, EasingFunctionBase>(nameof(AnimationEasingFunction),
new QuadraticEase { EasingMode = EasingMode.EaseOut });
@ -58,7 +62,8 @@ namespace MapControl
DependencyPropertyHelper.Register<MapBase, double>(nameof(ViewScale), 0d);
private static readonly DependencyProperty AnimatedCenterProperty =
DependencyPropertyHelper.Register<MapBase, Windows.Foundation.Point>(nameof(AnimatedCenter), new Windows.Foundation.Point(),
DependencyPropertyHelper.Register<MapBase, Windows.Foundation.Point>(nameof(AnimatedCenter),
new Windows.Foundation.Point(),
(map, oldValue, newValue) => map.Center = new Location(newValue.Y, newValue.X));
private Windows.Foundation.Point AnimatedCenter => (Windows.Foundation.Point)GetValue(AnimatedCenterProperty);