diff --git a/src/Avalonia.Base/AttachedProperty.cs b/src/Avalonia.Base/AttachedProperty.cs
index 31b6cad8abc..4a09f2a80af 100644
--- a/src/Avalonia.Base/AttachedProperty.cs
+++ b/src/Avalonia.Base/AttachedProperty.cs
@@ -32,9 +32,14 @@ public AttachedProperty(
///
/// The owner type.
/// The property.
- public new AttachedProperty AddOwner() where TOwner : AvaloniaObject
+ public new AttachedProperty AddOwner(StyledPropertyMetadata? metadata = null) where TOwner : AvaloniaObject
{
AvaloniaPropertyRegistry.Instance.Register(typeof(TOwner), this);
+ if (metadata != null)
+ {
+ OverrideMetadata(metadata);
+ }
+
return this;
}
}
diff --git a/src/Avalonia.Base/Input/GestureRecognizers/GestureRecognizerCollection.cs b/src/Avalonia.Base/Input/GestureRecognizers/GestureRecognizerCollection.cs
index a202d6b5bcf..3b9b2d0de61 100644
--- a/src/Avalonia.Base/Input/GestureRecognizers/GestureRecognizerCollection.cs
+++ b/src/Avalonia.Base/Input/GestureRecognizers/GestureRecognizerCollection.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.LogicalTree;
-using Avalonia.Styling;
+using Avalonia.Reactive;
namespace Avalonia.Input.GestureRecognizers
{
@@ -11,13 +11,13 @@ public class GestureRecognizerCollection : IReadOnlyCollection? _recognizers;
private Dictionary? _pointerGrabs;
-
-
+
+
public GestureRecognizerCollection(IInputElement inputElement)
{
_inputElement = inputElement;
}
-
+
public void Add(IGestureRecognizer recognizer)
{
if (_recognizers == null)
@@ -31,14 +31,13 @@ public void Add(IGestureRecognizer recognizer)
recognizer.Initialize(_inputElement, this);
// Hacks to make bindings work
-
+
if (_inputElement is ILogical logicalParent && recognizer is ISetLogicalParent logical)
{
logical.SetParent(logicalParent);
if (recognizer is StyledElement styleableRecognizer
&& _inputElement is StyledElement styleableParent)
- styleableRecognizer.Bind(StyledElement.TemplatedParentProperty,
- styleableParent.GetObservable(StyledElement.TemplatedParentProperty));
+ styleableParent.GetObservable(StyledElement.TemplatedParentProperty).Subscribe(parent => styleableRecognizer.TemplatedParent = parent);
}
}
@@ -58,7 +57,7 @@ internal bool HandlePointerPressed(PointerPressedEventArgs e)
return false;
foreach (var r in _recognizers)
{
- if(e.Handled)
+ if (e.Handled)
break;
r.PointerPressed(e);
}
diff --git a/src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs b/src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs
index 991694cc60c..6784677520e 100644
--- a/src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs
+++ b/src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs
@@ -13,22 +13,18 @@ public class PullGestureRecognizer : StyledElement, IGestureRecognizer
private Point _initialPosition;
private int _gestureId;
private IPointer? _tracking;
- private PullDirection _pullDirection;
private bool _pullInProgress;
///
/// Defines the property.
///
- public static readonly DirectProperty PullDirectionProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(PullDirection),
- o => o.PullDirection,
- (o, v) => o.PullDirection = v);
+ public static readonly StyledProperty PullDirectionProperty =
+ AvaloniaProperty.Register(nameof(PullDirection));
public PullDirection PullDirection
{
- get => _pullDirection;
- set => SetAndRaise(PullDirectionProperty, ref _pullDirection, value);
+ get => GetValue(PullDirectionProperty);
+ set => SetValue(PullDirectionProperty, value);
}
public PullGestureRecognizer(PullDirection pullDirection)
diff --git a/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs b/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs
index 7c1ee13eed8..1ad2f292ca1 100644
--- a/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs
+++ b/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs
@@ -17,61 +17,45 @@ public class ScrollGestureRecognizer
private IPointer? _tracking;
private IInputElement? _target;
private IGestureRecognizerActionsDispatcher? _actions;
- private bool _canHorizontallyScroll;
- private bool _canVerticallyScroll;
private int _gestureId;
- private int _scrollStartDistance = 30;
private Point _pointerPressedPoint;
private VelocityTracker? _velocityTracker;
// Movement per second
private Vector _inertia;
private ulong? _lastMoveTimestamp;
- private bool _isScrollInertiaEnabled;
///
/// Defines the property.
///
- public static readonly DirectProperty CanHorizontallyScrollProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(CanHorizontallyScroll),
- o => o.CanHorizontallyScroll,
- (o, v) => o.CanHorizontallyScroll = v);
+ public static readonly StyledProperty CanHorizontallyScrollProperty =
+ AvaloniaProperty.Register(nameof(CanHorizontallyScroll));
///
/// Defines the property.
///
- public static readonly DirectProperty CanVerticallyScrollProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(CanVerticallyScroll),
- o => o.CanVerticallyScroll,
- (o, v) => o.CanVerticallyScroll = v);
+ public static readonly StyledProperty CanVerticallyScrollProperty =
+ AvaloniaProperty.Register(nameof(CanVerticallyScroll));
///
/// Defines the property.
///
- public static readonly DirectProperty IsScrollInertiaEnabledProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(IsScrollInertiaEnabled),
- o => o.IsScrollInertiaEnabled,
- (o, v) => o.IsScrollInertiaEnabled = v);
+ public static readonly StyledProperty IsScrollInertiaEnabledProperty =
+ AvaloniaProperty.Register(nameof(IsScrollInertiaEnabled));
///
/// Defines the property.
///
- public static readonly DirectProperty ScrollStartDistanceProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(ScrollStartDistance),
- o => o.ScrollStartDistance,
- (o, v) => o.ScrollStartDistance = v);
+ public static readonly StyledProperty ScrollStartDistanceProperty =
+ AvaloniaProperty.Register(nameof(ScrollStartDistance), 30);
///
/// Gets or sets a value indicating whether the content can be scrolled horizontally.
///
public bool CanHorizontallyScroll
{
- get => _canHorizontallyScroll;
- set => SetAndRaise(CanHorizontallyScrollProperty, ref _canHorizontallyScroll, value);
+ get => GetValue(CanHorizontallyScrollProperty);
+ set => SetValue(CanHorizontallyScrollProperty, value);
}
///
@@ -79,8 +63,8 @@ public bool CanHorizontallyScroll
///
public bool CanVerticallyScroll
{
- get => _canVerticallyScroll;
- set => SetAndRaise(CanVerticallyScrollProperty, ref _canVerticallyScroll, value);
+ get => GetValue(CanVerticallyScrollProperty);
+ set => SetValue(CanVerticallyScrollProperty, value);
}
///
@@ -88,8 +72,8 @@ public bool CanVerticallyScroll
///
public bool IsScrollInertiaEnabled
{
- get => _isScrollInertiaEnabled;
- set => SetAndRaise(IsScrollInertiaEnabledProperty, ref _isScrollInertiaEnabled, value);
+ get => GetValue(IsScrollInertiaEnabledProperty);
+ set => SetValue(IsScrollInertiaEnabledProperty, value);
}
///
@@ -97,8 +81,8 @@ public bool IsScrollInertiaEnabled
///
public int ScrollStartDistance
{
- get => _scrollStartDistance;
- set => SetAndRaise(ScrollStartDistanceProperty, ref _scrollStartDistance, value);
+ get => GetValue(ScrollStartDistanceProperty);
+ set => SetValue(ScrollStartDistanceProperty, value);
}
@@ -137,8 +121,8 @@ public void PointerMoved(PointerEventArgs e)
// Correct _trackedRootPoint with ScrollStartDistance, so scrolling does not start with a skip of ScrollStartDistance
_trackedRootPoint = new Point(
- _trackedRootPoint.X - (_trackedRootPoint.X >= rootPoint.X ? _scrollStartDistance : -_scrollStartDistance),
- _trackedRootPoint.Y - (_trackedRootPoint.Y >= rootPoint.Y ? _scrollStartDistance : -_scrollStartDistance));
+ _trackedRootPoint.X - (_trackedRootPoint.X >= rootPoint.X ? ScrollStartDistance : -ScrollStartDistance),
+ _trackedRootPoint.Y - (_trackedRootPoint.Y >= rootPoint.Y ? ScrollStartDistance : -ScrollStartDistance));
_actions!.Capture(e.Pointer, this);
}
diff --git a/src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs b/src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs
index 525a543b702..8e57f9a9025 100644
--- a/src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs
+++ b/src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs
@@ -48,8 +48,6 @@ public PixelRect SourceRect
public CroppedBitmap()
{
- Source = null;
- SourceRect = default;
}
public CroppedBitmap(IImage source, PixelRect sourceRect)
diff --git a/src/Avalonia.Base/StyledElement.cs b/src/Avalonia.Base/StyledElement.cs
index cbdf3c3c1e2..b51093b40c9 100644
--- a/src/Avalonia.Base/StyledElement.cs
+++ b/src/Avalonia.Base/StyledElement.cs
@@ -67,8 +67,7 @@ public class StyledElement : Animatable,
public static readonly DirectProperty TemplatedParentProperty =
AvaloniaProperty.RegisterDirect(
nameof(TemplatedParent),
- o => o.TemplatedParent,
- (o ,v) => o.TemplatedParent = v);
+ o => o.TemplatedParent);
///
/// Defines the property.
diff --git a/src/Avalonia.Base/StyledProperty.cs b/src/Avalonia.Base/StyledProperty.cs
index 8695918c185..50528400131 100644
--- a/src/Avalonia.Base/StyledProperty.cs
+++ b/src/Avalonia.Base/StyledProperty.cs
@@ -56,9 +56,14 @@ public StyledProperty(
///
/// The type of the additional owner.
/// The property.
- public StyledProperty AddOwner() where TOwner : AvaloniaObject
+ public StyledProperty AddOwner(StyledPropertyMetadata? metadata = null) where TOwner : AvaloniaObject
{
AvaloniaPropertyRegistry.Instance.Register(typeof(TOwner), this);
+ if (metadata != null)
+ {
+ OverrideMetadata(metadata);
+ }
+
return this;
}
diff --git a/src/Avalonia.Controls/Button.cs b/src/Avalonia.Controls/Button.cs
index 1ec6f8dabc7..f48d7a7cc1d 100644
--- a/src/Avalonia.Controls/Button.cs
+++ b/src/Avalonia.Controls/Button.cs
@@ -1,11 +1,9 @@
using System;
-using System.Diagnostics;
using System.Linq;
using System.Windows.Input;
using Avalonia.Automation.Peers;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
-using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
@@ -48,9 +46,8 @@ public class Button : ContentControl, ICommandSource, IClickableControl
///
/// Defines the property.
///
- public static readonly DirectProperty