mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Use AddOwner for MapBase.Foreground
This commit is contained in:
parent
3c907c3345
commit
197f004eeb
|
|
@ -46,5 +46,12 @@ namespace MapControl
|
||||||
|
|
||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static StyledProperty<TValue> AddOwner<TOwner, TValue>(
|
||||||
|
StyledProperty<TValue> property)
|
||||||
|
where TOwner : AvaloniaObject
|
||||||
|
{
|
||||||
|
return property.AddOwner<TOwner>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ global using Avalonia;
|
||||||
using Avalonia.Animation;
|
using Avalonia.Animation;
|
||||||
using Avalonia.Animation.Easings;
|
using Avalonia.Animation.Easings;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Documents;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
@ -15,6 +16,9 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public partial class MapBase
|
public partial class MapBase
|
||||||
{
|
{
|
||||||
|
public static readonly StyledProperty<IBrush> ForegroundProperty =
|
||||||
|
DependencyPropertyHelper.AddOwner<MapBase, IBrush>(TextElement.ForegroundProperty);
|
||||||
|
|
||||||
public static readonly StyledProperty<Easing> AnimationEasingProperty =
|
public static readonly StyledProperty<Easing> AnimationEasingProperty =
|
||||||
DependencyPropertyHelper.Register<MapBase, Easing>(nameof(AnimationEasing), new QuadraticEaseOut());
|
DependencyPropertyHelper.Register<MapBase, Easing>(nameof(AnimationEasing), new QuadraticEaseOut());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@
|
||||||
<DefineConstants>AVALONIA</DefineConstants>
|
<DefineConstants>AVALONIA</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\..\MapControl.snk" Link="MapControl.snk" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\Shared\*.cs" />
|
<Compile Include="..\Shared\*.cs" />
|
||||||
<Compile Remove="..\Shared\BindingHelper.cs" />
|
<Compile Remove="..\Shared\BindingHelper.cs" />
|
||||||
|
|
@ -33,10 +37,6 @@
|
||||||
<Compile Remove="..\Shared\ViewTransform.cs" />
|
<Compile Remove="..\Shared\ViewTransform.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="..\..\MapControl.snk" Link="MapControl.snk" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.0.10" />
|
<PackageReference Include="Avalonia" Version="11.0.10" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,12 @@ using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
#elif UWP
|
#elif UWP
|
||||||
using Windows.UI;
|
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
#elif WINUI
|
#elif WINUI
|
||||||
using Microsoft.UI;
|
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Media;
|
using Microsoft.UI.Xaml.Media;
|
||||||
#elif AVALONIA
|
#elif AVALONIA
|
||||||
using Avalonia.Media;
|
|
||||||
using Brush = Avalonia.Media.IBrush;
|
using Brush = Avalonia.Media.IBrush;
|
||||||
using DependencyProperty = Avalonia.AvaloniaProperty;
|
using DependencyProperty = Avalonia.AvaloniaProperty;
|
||||||
using UIElement = Avalonia.Controls.Control;
|
using UIElement = Avalonia.Controls.Control;
|
||||||
|
|
@ -40,9 +37,6 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public static TimeSpan ImageFadeDuration { get; set; } = TimeSpan.FromSeconds(0.1);
|
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 =
|
public static readonly DependencyProperty AnimationDurationProperty =
|
||||||
DependencyPropertyHelper.Register<MapBase, TimeSpan>(nameof(AnimationDuration), TimeSpan.FromSeconds(0.3));
|
DependencyPropertyHelper.Register<MapBase, TimeSpan>(nameof(AnimationDuration), TimeSpan.FromSeconds(0.3));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,24 +73,9 @@ namespace MapControl
|
||||||
return DependencyProperty.RegisterReadOnly(name, typeof(TValue), typeof(TOwner), new PropertyMetadata(defaultValue));
|
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>(
|
public static DependencyProperty AddOwner<TOwner, TValue>(
|
||||||
DependencyProperty property,
|
DependencyProperty property,
|
||||||
Action<TOwner, TValue, TValue> changed)
|
Action<TOwner, TValue, TValue> changed = null)
|
||||||
where TOwner : DependencyObject
|
where TOwner : DependencyObject
|
||||||
{
|
{
|
||||||
FrameworkPropertyMetadata metadata = null;
|
FrameworkPropertyMetadata metadata = null;
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,17 @@
|
||||||
// Licensed under the Microsoft Public License (Ms-PL)
|
// Licensed under the Microsoft Public License (Ms-PL)
|
||||||
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Animation;
|
using System.Windows.Media.Animation;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
{
|
{
|
||||||
public partial class MapBase
|
public partial class MapBase
|
||||||
{
|
{
|
||||||
|
public static readonly DependencyProperty ForegroundProperty =
|
||||||
|
DependencyPropertyHelper.AddOwner<MapBase, Brush>(TextElement.ForegroundProperty);
|
||||||
|
|
||||||
public static readonly DependencyProperty AnimationEasingFunctionProperty =
|
public static readonly DependencyProperty AnimationEasingFunctionProperty =
|
||||||
DependencyPropertyHelper.Register<MapBase, IEasingFunction>(nameof(AnimationEasingFunction),
|
DependencyPropertyHelper.Register<MapBase, IEasingFunction>(nameof(AnimationEasingFunction),
|
||||||
new QuadraticEase { EasingMode = EasingMode.EaseOut });
|
new QuadraticEase { EasingMode = EasingMode.EaseOut });
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ namespace MapControl
|
||||||
public class MapContentControl : ContentControl
|
public class MapContentControl : ContentControl
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty AutoCollapseProperty =
|
public static readonly DependencyProperty AutoCollapseProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapContentControl>(MapPanel.AutoCollapseProperty);
|
DependencyPropertyHelper.AddOwner<MapContentControl, bool>(MapPanel.AutoCollapseProperty);
|
||||||
|
|
||||||
public static readonly DependencyProperty LocationProperty =
|
public static readonly DependencyProperty LocationProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapContentControl>(MapPanel.LocationProperty);
|
DependencyPropertyHelper.AddOwner<MapContentControl, Location>(MapPanel.LocationProperty);
|
||||||
|
|
||||||
static MapContentControl()
|
static MapContentControl()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ namespace MapControl
|
||||||
public partial class MapItem
|
public partial class MapItem
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty AutoCollapseProperty =
|
public static readonly DependencyProperty AutoCollapseProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapItem>(MapPanel.AutoCollapseProperty);
|
DependencyPropertyHelper.AddOwner<MapItem, bool>(MapPanel.AutoCollapseProperty);
|
||||||
|
|
||||||
public static readonly DependencyProperty LocationProperty =
|
public static readonly DependencyProperty LocationProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty,
|
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty,
|
||||||
|
|
|
||||||
|
|
@ -13,64 +13,49 @@ namespace MapControl
|
||||||
public partial class MapOverlay
|
public partial class MapOverlay
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty FontFamilyProperty =
|
public static readonly DependencyProperty FontFamilyProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontFamilyProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, FontFamily>(TextElement.FontFamilyProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty FontSizeProperty =
|
public static readonly DependencyProperty FontSizeProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontSizeProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, double>(TextElement.FontSizeProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty FontStyleProperty =
|
public static readonly DependencyProperty FontStyleProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontStyleProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, FontStyle>(TextElement.FontStyleProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty FontStretchProperty =
|
public static readonly DependencyProperty FontStretchProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontStretchProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, FontStretch>(TextElement.FontStretchProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty FontWeightProperty =
|
public static readonly DependencyProperty FontWeightProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.FontWeightProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, FontWeight>(TextElement.FontWeightProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty ForegroundProperty =
|
public static readonly DependencyProperty ForegroundProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(TextElement.ForegroundProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, Brush>(TextElement.ForegroundProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeProperty =
|
public static readonly DependencyProperty StrokeProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, Brush>(Shape.StrokeProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeThicknessProperty =
|
public static readonly DependencyProperty StrokeThicknessProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeThicknessProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, double>(Shape.StrokeThicknessProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeDashArrayProperty =
|
public static readonly DependencyProperty StrokeDashArrayProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashArrayProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, DoubleCollection>(Shape.StrokeDashArrayProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeDashOffsetProperty =
|
public static readonly DependencyProperty StrokeDashOffsetProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashOffsetProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, double>(Shape.StrokeDashOffsetProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeDashCapProperty =
|
public static readonly DependencyProperty StrokeDashCapProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeDashCapProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, PenLineCap>(Shape.StrokeDashCapProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeStartLineCapProperty =
|
public static readonly DependencyProperty StrokeStartLineCapProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeStartLineCapProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, PenLineCap>(Shape.StrokeStartLineCapProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeEndLineCapProperty =
|
public static readonly DependencyProperty StrokeEndLineCapProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeEndLineCapProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, PenLineCap>(Shape.StrokeEndLineCapProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeLineJoinProperty =
|
public static readonly DependencyProperty StrokeLineJoinProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeLineJoinProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, PenLineJoin>(Shape.StrokeLineJoinProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
public static readonly DependencyProperty StrokeMiterLimitProperty =
|
public static readonly DependencyProperty StrokeMiterLimitProperty =
|
||||||
DependencyPropertyHelper.AddOwner<MapOverlay>(Shape.StrokeMiterLimitProperty,
|
DependencyPropertyHelper.AddOwner<MapOverlay, double>(Shape.StrokeMiterLimitProperty);
|
||||||
FrameworkPropertyMetadataOptions.AffectsRender);
|
|
||||||
|
|
||||||
protected override void OnInitialized(EventArgs e)
|
protected override void OnInitialized(EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
public partial class MapBase
|
public partial class MapBase
|
||||||
{
|
{
|
||||||
|
public static readonly DependencyProperty ForegroundProperty =
|
||||||
|
DependencyPropertyHelper.Register<MapBase, Brush>(nameof(Foreground),
|
||||||
|
new SolidColorBrush(Colors.Black));
|
||||||
|
|
||||||
public static readonly DependencyProperty AnimationEasingFunctionProperty =
|
public static readonly DependencyProperty AnimationEasingFunctionProperty =
|
||||||
DependencyPropertyHelper.Register<MapBase, EasingFunctionBase>(nameof(AnimationEasingFunction),
|
DependencyPropertyHelper.Register<MapBase, EasingFunctionBase>(nameof(AnimationEasingFunction),
|
||||||
new QuadraticEase { EasingMode = EasingMode.EaseOut });
|
new QuadraticEase { EasingMode = EasingMode.EaseOut });
|
||||||
|
|
@ -58,7 +62,8 @@ namespace MapControl
|
||||||
DependencyPropertyHelper.Register<MapBase, double>(nameof(ViewScale), 0d);
|
DependencyPropertyHelper.Register<MapBase, double>(nameof(ViewScale), 0d);
|
||||||
|
|
||||||
private static readonly DependencyProperty AnimatedCenterProperty =
|
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));
|
(map, oldValue, newValue) => map.Center = new Location(newValue.Y, newValue.X));
|
||||||
|
|
||||||
private Windows.Foundation.Point AnimatedCenter => (Windows.Foundation.Point)GetValue(AnimatedCenterProperty);
|
private Windows.Foundation.Point AnimatedCenter => (Windows.Foundation.Point)GetValue(AnimatedCenterProperty);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue