diff --git a/src/Avalonia.Base/AttachedProperty.cs b/src/Avalonia.Base/AttachedProperty.cs
index 31b6cad8ab..4a09f2a80a 100644
--- a/src/Avalonia.Base/AttachedProperty.cs
+++ b/src/Avalonia.Base/AttachedProperty.cs
@@ -32,9 +32,14 @@ namespace Avalonia
///
/// 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 a202d6b5bc..3b9b2d0de6 100644
--- a/src/Avalonia.Base/Input/GestureRecognizers/GestureRecognizerCollection.cs
+++ b/src/Avalonia.Base/Input/GestureRecognizers/GestureRecognizerCollection.cs
@@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.LogicalTree;
-using Avalonia.Styling;
+using Avalonia.Reactive;
namespace Avalonia.Input.GestureRecognizers
{
@@ -11,13 +11,13 @@ namespace Avalonia.Input.GestureRecognizers
private readonly IInputElement _inputElement;
private List? _recognizers;
private Dictionary? _pointerGrabs;
-
-
+
+
public GestureRecognizerCollection(IInputElement inputElement)
{
_inputElement = inputElement;
}
-
+
public void Add(IGestureRecognizer recognizer)
{
if (_recognizers == null)
@@ -31,14 +31,13 @@ namespace Avalonia.Input.GestureRecognizers
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 @@ namespace Avalonia.Input.GestureRecognizers
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 991694cc60..6784677520 100644
--- a/src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs
+++ b/src/Avalonia.Base/Input/GestureRecognizers/PullGestureRecognizer.cs
@@ -13,22 +13,18 @@ namespace Avalonia.Input
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 7c1ee13eed..1ad2f292ca 100644
--- a/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs
+++ b/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs
@@ -17,61 +17,45 @@ namespace Avalonia.Input.GestureRecognizers
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 @@ namespace Avalonia.Input.GestureRecognizers
///
public bool CanVerticallyScroll
{
- get => _canVerticallyScroll;
- set => SetAndRaise(CanVerticallyScrollProperty, ref _canVerticallyScroll, value);
+ get => GetValue(CanVerticallyScrollProperty);
+ set => SetValue(CanVerticallyScrollProperty, value);
}
///
@@ -88,8 +72,8 @@ namespace Avalonia.Input.GestureRecognizers
///
public bool IsScrollInertiaEnabled
{
- get => _isScrollInertiaEnabled;
- set => SetAndRaise(IsScrollInertiaEnabledProperty, ref _isScrollInertiaEnabled, value);
+ get => GetValue(IsScrollInertiaEnabledProperty);
+ set => SetValue(IsScrollInertiaEnabledProperty, value);
}
///
@@ -97,8 +81,8 @@ namespace Avalonia.Input.GestureRecognizers
///
public int ScrollStartDistance
{
- get => _scrollStartDistance;
- set => SetAndRaise(ScrollStartDistanceProperty, ref _scrollStartDistance, value);
+ get => GetValue(ScrollStartDistanceProperty);
+ set => SetValue(ScrollStartDistanceProperty, value);
}
@@ -137,8 +121,8 @@ namespace Avalonia.Input.GestureRecognizers
// 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 525a543b70..8e57f9a902 100644
--- a/src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs
+++ b/src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs
@@ -48,8 +48,6 @@ namespace Avalonia.Media.Imaging
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 cbdf3c3c1e..b51093b40c 100644
--- a/src/Avalonia.Base/StyledElement.cs
+++ b/src/Avalonia.Base/StyledElement.cs
@@ -67,8 +67,7 @@ namespace Avalonia
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 8695918c18..5052840013 100644
--- a/src/Avalonia.Base/StyledProperty.cs
+++ b/src/Avalonia.Base/StyledProperty.cs
@@ -56,9 +56,14 @@ namespace Avalonia
///
/// 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/Calendar/Calendar.cs b/src/Avalonia.Controls/Calendar/Calendar.cs
index 3300292857..10aadfa759 100644
--- a/src/Avalonia.Controls/Calendar/Calendar.cs
+++ b/src/Avalonia.Controls/Calendar/Calendar.cs
@@ -232,14 +232,9 @@ namespace Avalonia.Controls
internal const int RowsPerYear = 3;
internal const int ColumnsPerYear = 4;
- private DateTime? _selectedDate;
private DateTime _selectedMonth;
private DateTime _selectedYear;
- private DateTime _displayDate = DateTime.Today;
- private DateTime? _displayDateStart;
- private DateTime? _displayDateEnd;
-
private bool _isShiftPressed;
private bool _displayDateIsChanging;
@@ -396,13 +391,13 @@ namespace Avalonia.Controls
}
case CalendarMode.Year:
{
- DisplayDate = SelectedMonth;
+ SetCurrentValue(DisplayDateProperty, SelectedMonth);
SelectedYear = SelectedMonth;
break;
}
case CalendarMode.Decade:
{
- DisplayDate = SelectedYear;
+ SetCurrentValue(DisplayDateProperty, SelectedYear);
SelectedMonth = SelectedYear;
break;
}
@@ -472,7 +467,7 @@ namespace Avalonia.Controls
if (IsValidSelectionMode(e.NewValue!))
{
_displayDateIsChanging = true;
- SelectedDate = null;
+ SetCurrentValue(SelectedDateProperty, null);
_displayDateIsChanging = false;
SelectedDates.Clear();
}
@@ -497,11 +492,8 @@ namespace Avalonia.Controls
|| mode == CalendarSelectionMode.None;
}
- public static readonly DirectProperty SelectedDateProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(SelectedDate),
- o => o.SelectedDate,
- (o, v) => o.SelectedDate = v,
+ public static readonly StyledProperty SelectedDateProperty =
+ AvaloniaProperty.Register(nameof(SelectedDate),
defaultBindingMode: BindingMode.TwoWay);
///
@@ -529,8 +521,8 @@ namespace Avalonia.Controls
///
public DateTime? SelectedDate
{
- get { return _selectedDate; }
- set { SetAndRaise(SelectedDateProperty, ref _selectedDate, value); }
+ get => GetValue(SelectedDateProperty);
+ set => SetValue(SelectedDateProperty, value);
}
private void OnSelectedDateChanged(AvaloniaPropertyChangedEventArgs e)
{
@@ -726,11 +718,8 @@ namespace Avalonia.Controls
}
}
- public static readonly DirectProperty DisplayDateProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(DisplayDate),
- o => o.DisplayDate,
- (o, v) => o.DisplayDate = v,
+ public static readonly StyledProperty DisplayDateProperty =
+ AvaloniaProperty.Register(nameof(DisplayDate),
defaultBindingMode: BindingMode.TwoWay);
///
@@ -760,8 +749,8 @@ namespace Avalonia.Controls
///
public DateTime DisplayDate
{
- get { return _displayDate; }
- set { SetAndRaise(DisplayDateProperty, ref _displayDate, value); }
+ get => GetValue(DisplayDateProperty);
+ set => SetValue(DisplayDateProperty, value);
}
internal DateTime DisplayDateInternal { get; private set; }
@@ -796,11 +785,8 @@ namespace Avalonia.Controls
DisplayDateChanged?.Invoke(this, e);
}
- public static readonly DirectProperty DisplayDateStartProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(DisplayDateStart),
- o => o.DisplayDateStart,
- (o, v) => o.DisplayDateStart = v,
+ public static readonly StyledProperty DisplayDateStartProperty =
+ AvaloniaProperty.Register(nameof(DisplayDateStart),
defaultBindingMode: BindingMode.TwoWay);
///
/// Gets or sets the first date to be displayed.
@@ -814,8 +800,8 @@ namespace Avalonia.Controls
///
public DateTime? DisplayDateStart
{
- get { return _displayDateStart; }
- set { SetAndRaise(DisplayDateStartProperty, ref _displayDateStart, value); }
+ get => GetValue(DisplayDateStartProperty);
+ set => SetValue(DisplayDateStartProperty, value);
}
private void OnDisplayDateStartChanged(AvaloniaPropertyChangedEventArgs e)
{
@@ -831,7 +817,7 @@ namespace Avalonia.Controls
if (selectedDateMin.HasValue && DateTime.Compare(selectedDateMin.Value, newValue.Value) < 0)
{
- DisplayDateStart = selectedDateMin.Value;
+ SetCurrentValue(DisplayDateStartProperty, selectedDateMin.Value);
return;
}
@@ -839,14 +825,14 @@ namespace Avalonia.Controls
// DisplayDateEnd = DisplayDateStart
if (DateTime.Compare(newValue.Value, DisplayDateRangeEnd) > 0)
{
- DisplayDateEnd = DisplayDateStart;
+ SetCurrentValue(DisplayDateEndProperty, DisplayDateStart);
}
// If DisplayDate < DisplayDateStart,
// DisplayDate = DisplayDateStart
if (DateTimeHelper.CompareYearMonth(newValue.Value, DisplayDateInternal) > 0)
{
- DisplayDate = newValue.Value;
+ SetCurrentValue(DisplayDateProperty, newValue.Value);
}
}
UpdateMonths();
@@ -905,11 +891,8 @@ namespace Avalonia.Controls
get { return DisplayDateStart.GetValueOrDefault(DateTime.MinValue); }
}
- public static readonly DirectProperty DisplayDateEndProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(DisplayDateEnd),
- o => o.DisplayDateEnd,
- (o, v) => o.DisplayDateEnd = v,
+ public static readonly StyledProperty DisplayDateEndProperty =
+ AvaloniaProperty.Register(nameof(DisplayDateEnd),
defaultBindingMode: BindingMode.TwoWay);
///
@@ -924,8 +907,8 @@ namespace Avalonia.Controls
///
public DateTime? DisplayDateEnd
{
- get { return _displayDateEnd; }
- set { SetAndRaise(DisplayDateEndProperty, ref _displayDateEnd, value); }
+ get => GetValue(DisplayDateEndProperty);
+ set => SetValue(DisplayDateEndProperty, value);
}
private void OnDisplayDateEndChanged(AvaloniaPropertyChangedEventArgs e)
@@ -942,7 +925,7 @@ namespace Avalonia.Controls
if (selectedDateMax.HasValue && DateTime.Compare(selectedDateMax.Value, newValue.Value) > 0)
{
- DisplayDateEnd = selectedDateMax.Value;
+ SetCurrentValue(DisplayDateEndProperty, selectedDateMax.Value);
return;
}
@@ -950,7 +933,7 @@ namespace Avalonia.Controls
// DisplayDateEnd = DisplayDateStart
if (DateTime.Compare(newValue.Value, DisplayDateRangeStart) < 0)
{
- DisplayDateEnd = DisplayDateStart;
+ SetCurrentValue(DisplayDateEndProperty, DisplayDateStart);
return;
}
@@ -958,7 +941,7 @@ namespace Avalonia.Controls
// DisplayDate = DisplayDateEnd
if (DateTimeHelper.CompareYearMonth(newValue.Value, DisplayDateInternal) < 0)
{
- DisplayDate = newValue.Value;
+ SetCurrentValue(DisplayDateProperty, newValue.Value);
}
}
UpdateMonths();
@@ -1284,7 +1267,7 @@ namespace Avalonia.Controls
{
LastSelectedDate = d.Value;
}
- DisplayDate = d.Value;
+ SetCurrentValue(DisplayDateProperty, d.Value);
}
}
else
@@ -1332,7 +1315,7 @@ namespace Avalonia.Controls
{
LastSelectedDate = d.Value;
}
- DisplayDate = d.Value;
+ SetCurrentValue(DisplayDateProperty, d.Value);
}
}
else
@@ -1719,7 +1702,7 @@ namespace Avalonia.Controls
if (ctrl)
{
SelectedMonth = DisplayDateInternal;
- DisplayMode = CalendarMode.Year;
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Year);
}
else
{
@@ -1733,7 +1716,7 @@ namespace Avalonia.Controls
if (ctrl)
{
SelectedYear = SelectedMonth;
- DisplayMode = CalendarMode.Decade;
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Decade);
}
else
{
@@ -1770,8 +1753,8 @@ namespace Avalonia.Controls
{
if (ctrl)
{
- DisplayDate = SelectedMonth;
- DisplayMode = CalendarMode.Month;
+ SetCurrentValue(DisplayDateProperty, SelectedMonth);
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Month);
}
else
{
@@ -1785,7 +1768,7 @@ namespace Avalonia.Controls
if (ctrl)
{
SelectedMonth = SelectedYear;
- DisplayMode = CalendarMode.Year;
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Year);
}
else
{
@@ -1850,14 +1833,14 @@ namespace Avalonia.Controls
{
case CalendarMode.Year:
{
- DisplayDate = SelectedMonth;
- DisplayMode = CalendarMode.Month;
+ SetCurrentValue(DisplayDateProperty, SelectedMonth);
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Month);
return true;
}
case CalendarMode.Decade:
{
SelectedMonth = SelectedYear;
- DisplayMode = CalendarMode.Year;
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Year);
return true;
}
}
@@ -2103,7 +2086,8 @@ namespace Avalonia.Controls
///
public Calendar()
{
- UpdateDisplayDate(this, this.DisplayDate, DateTime.MinValue);
+ SetCurrentValue(DisplayDateProperty, DateTime.Today);
+ UpdateDisplayDate(this, DisplayDate, DateTime.MinValue);
BlackoutDates = new CalendarBlackoutDatesCollection(this);
SelectedDates = new SelectedDatesCollection(this);
RemovedItems = new Collection();
diff --git a/src/Avalonia.Controls/Calendar/CalendarItem.cs b/src/Avalonia.Controls/Calendar/CalendarItem.cs
index 3d436b4485..2e3f1f96ce 100644
--- a/src/Avalonia.Controls/Calendar/CalendarItem.cs
+++ b/src/Avalonia.Controls/Calendar/CalendarItem.cs
@@ -41,7 +41,6 @@ namespace Avalonia.Controls.Primitives
private Button? _headerButton;
private Button? _nextButton;
private Button? _previousButton;
- private ITemplate? _dayTitleTemplate;
private DateTime _currentMonth;
private bool _isMouseLeftButtonDown;
@@ -61,17 +60,15 @@ namespace Avalonia.Controls.Primitives
set { SetValue(HeaderBackgroundProperty, value); }
}
- public static readonly DirectProperty?> DayTitleTemplateProperty =
- AvaloniaProperty.RegisterDirect?>(
+ public static readonly StyledProperty?> DayTitleTemplateProperty =
+ AvaloniaProperty.Register?>(
nameof(DayTitleTemplate),
- o => o.DayTitleTemplate,
- (o,v) => o.DayTitleTemplate = v,
defaultBindingMode: BindingMode.OneTime);
public ITemplate? DayTitleTemplate
{
- get { return _dayTitleTemplate; }
- set { SetAndRaise(DayTitleTemplateProperty, ref _dayTitleTemplate, value); }
+ get => GetValue(DayTitleTemplateProperty);
+ set => SetValue(DayTitleTemplateProperty, value);
}
///
@@ -176,9 +173,8 @@ namespace Avalonia.Controls.Primitives
for (int i = 0; i < Calendar.RowsPerMonth; i++)
{
- if (_dayTitleTemplate != null)
+ if (DayTitleTemplate?.Build() is Control cell)
{
- var cell = _dayTitleTemplate.Build();
cell.DataContext = string.Empty;
cell.SetValue(Grid.RowProperty, 0);
cell.SetValue(Grid.ColumnProperty, i);
diff --git a/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs b/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs
index 6c2356b411..5ff04b1a99 100644
--- a/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs
+++ b/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.Properties.cs
@@ -11,29 +11,22 @@ namespace Avalonia.Controls
///
/// Defines the property.
///
- public static readonly DirectProperty DisplayDateProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(DisplayDate),
- o => o.DisplayDate,
- (o, v) => o.DisplayDate = v);
+ public static readonly StyledProperty DisplayDateProperty =
+ AvaloniaProperty.Register(nameof(DisplayDate));
///
/// Defines the property.
///
- public static readonly DirectProperty DisplayDateStartProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(DisplayDateStart),
- o => o.DisplayDateStart,
- (o, v) => o.DisplayDateStart = v);
+ public static readonly StyledProperty DisplayDateStartProperty =
+ AvaloniaProperty.Register(
+ nameof(DisplayDateStart));
///
/// Defines the property.
///
- public static readonly DirectProperty DisplayDateEndProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(DisplayDateEnd),
- o => o.DisplayDateEnd,
- (o, v) => o.DisplayDateEnd = v);
+ public static readonly StyledProperty DisplayDateEndProperty =
+ AvaloniaProperty.Register(
+ nameof(DisplayDateEnd));
///
/// Defines the property.
@@ -44,11 +37,9 @@ namespace Avalonia.Controls
///
/// Defines the property.
///
- public static readonly DirectProperty IsDropDownOpenProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(IsDropDownOpen),
- o => o.IsDropDownOpen,
- (o, v) => o.IsDropDownOpen = v);
+ public static readonly StyledProperty IsDropDownOpenProperty =
+ AvaloniaProperty.Register(
+ nameof(IsDropDownOpen));
///
/// Defines the property.
@@ -88,11 +79,8 @@ namespace Avalonia.Controls
///
/// Defines the property.
///
- public static readonly DirectProperty TextProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(Text),
- o => o.Text,
- (o, v) => o.Text = v);
+ public static readonly StyledProperty TextProperty =
+ AvaloniaProperty.Register(nameof(Text));
///
/// Defines the property.
@@ -141,8 +129,8 @@ namespace Avalonia.Controls
///
public DateTime DisplayDate
{
- get => _displayDate;
- set => SetAndRaise(DisplayDateProperty, ref _displayDate, value);
+ get => GetValue(DisplayDateProperty);
+ set => SetValue(DisplayDateProperty, value);
}
///
@@ -151,8 +139,8 @@ namespace Avalonia.Controls
/// The first date to display.
public DateTime? DisplayDateStart
{
- get => _displayDateStart;
- set => SetAndRaise(DisplayDateStartProperty, ref _displayDateStart, value);
+ get => GetValue(DisplayDateStartProperty);
+ set => SetValue(DisplayDateStartProperty, value);
}
///
@@ -161,8 +149,8 @@ namespace Avalonia.Controls
/// The last date to display.
public DateTime? DisplayDateEnd
{
- get => _displayDateEnd;
- set => SetAndRaise(DisplayDateEndProperty, ref _displayDateEnd, value);
+ get => GetValue(DisplayDateEndProperty);
+ set => SetValue(DisplayDateEndProperty, value);
}
///
@@ -188,8 +176,8 @@ namespace Avalonia.Controls
///
public bool IsDropDownOpen
{
- get => _isDropDownOpen;
- set => SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value);
+ get => GetValue(IsDropDownOpenProperty);
+ set => SetValue(IsDropDownOpenProperty, value);
}
///
@@ -264,8 +252,8 @@ namespace Avalonia.Controls
///
public string? Text
{
- get => _text;
- set => SetAndRaise(TextProperty, ref _text, value);
+ get => GetValue(TextProperty);
+ set => SetValue(TextProperty, value);
}
///
diff --git a/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.cs b/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.cs
index 869bdeabea..3f5d355b71 100644
--- a/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.cs
+++ b/src/Avalonia.Controls/CalendarDatePicker/CalendarDatePicker.cs
@@ -45,12 +45,7 @@ namespace Avalonia.Controls
private DateTime? _onOpenSelectedDate;
private bool _settingSelectedDate;
- private DateTime _displayDate;
- private DateTime? _displayDateStart;
- private DateTime? _displayDateEnd;
- private bool _isDropDownOpen;
private DateTime? _selectedDate;
- private string? _text;
private bool _suspendTextChangeHandler;
private bool _isPopupClosing;
private bool _ignoreButtonClick;
@@ -92,9 +87,9 @@ namespace Avalonia.Controls
///
public CalendarDatePicker()
{
- FirstDayOfWeek = DateTimeHelper.GetCurrentDateFormat().FirstDayOfWeek;
+ SetCurrentValue(FirstDayOfWeekProperty, DateTimeHelper.GetCurrentDateFormat().FirstDayOfWeek);
_defaultText = string.Empty;
- DisplayDate = DateTime.Today;
+ SetCurrentValue(DisplayDateProperty, DateTime.Today);
}
///
@@ -257,7 +252,7 @@ namespace Avalonia.Controls
Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
_settingSelectedDate = true;
- Text = DateTimeToString(day);
+ SetCurrentValue(TextProperty, DateTimeToString(day));
_settingSelectedDate = false;
OnDateSelected(addedDate, removedDate);
});
@@ -268,7 +263,7 @@ namespace Avalonia.Controls
// be changed by the Calendar
if ((day.Month != DisplayDate.Month || day.Year != DisplayDate.Year) && (_calendar == null || !_calendar.CalendarDatePickerDisplayDateFlag))
{
- DisplayDate = day;
+ SetCurrentValue(DisplayDateProperty, day);
}
if(_calendar != null)
@@ -317,7 +312,7 @@ namespace Avalonia.Controls
if (!_settingSelectedDate)
{
_settingSelectedDate = true;
- SelectedDate = null;
+ SetCurrentValue(SelectedDateProperty, null);
_settingSelectedDate = false;
}
}
@@ -400,7 +395,7 @@ namespace Avalonia.Controls
DateTime? newDate = DateTimeHelper.AddDays(selectedDate, e.Delta.Y > 0 ? -1 : 1);
if (newDate.HasValue && Calendar.IsValidDateSelection(_calendar, newDate.Value))
{
- SelectedDate = newDate;
+ SetCurrentValue(SelectedDateProperty, newDate);
e.Handled = true;
}
}
@@ -478,7 +473,7 @@ namespace Avalonia.Controls
{
if (SelectedDate.HasValue)
{
- Text = DateTimeToString(SelectedDate.Value);
+ SetCurrentValue(TextProperty, DateTimeToString(SelectedDate.Value));
}
else if (string.IsNullOrEmpty(_textBox.Text))
{
@@ -491,7 +486,7 @@ namespace Avalonia.Controls
if (date != null)
{
string? s = DateTimeToString((DateTime)date);
- Text = s;
+ SetCurrentValue(TextProperty, s);
}
}
}
@@ -547,7 +542,7 @@ namespace Avalonia.Controls
private void Calendar_DayButtonMouseUp(object? sender, PointerReleasedEventArgs e)
{
Focus();
- IsDropDownOpen = false;
+ SetCurrentValue(IsDropDownOpenProperty, false);
}
private void Calendar_DisplayDateChanged(object? sender, CalendarDateChangedEventArgs e)
@@ -564,13 +559,13 @@ namespace Avalonia.Controls
if (e.AddedItems.Count > 0 && SelectedDate.HasValue && DateTime.Compare((DateTime)e.AddedItems[0]!, SelectedDate.Value) != 0)
{
- SelectedDate = (DateTime?)e.AddedItems[0];
+ SetCurrentValue(SelectedDateProperty, (DateTime?)e.AddedItems[0]);
}
else
{
if (e.AddedItems.Count == 0)
{
- SelectedDate = null;
+ SetCurrentValue(SelectedDateProperty, null);
return;
}
@@ -578,7 +573,7 @@ namespace Avalonia.Controls
{
if (e.AddedItems.Count > 0)
{
- SelectedDate = (DateTime?)e.AddedItems[0];
+ SetCurrentValue(SelectedDateProperty, (DateTime?)e.AddedItems[0]);
}
}
}
@@ -600,18 +595,18 @@ namespace Avalonia.Controls
&& (e.Key == Key.Enter || e.Key == Key.Space || e.Key == Key.Escape))
{
Focus();
- IsDropDownOpen = false;
+ SetCurrentValue(IsDropDownOpenProperty, false);
if (e.Key == Key.Escape)
{
- SelectedDate = _onOpenSelectedDate;
+ SetCurrentValue(SelectedDateProperty, _onOpenSelectedDate);
}
}
}
private void TextBox_GotFocus(object? sender, RoutedEventArgs e)
{
- IsDropDownOpen = false;
+ SetCurrentValue(IsDropDownOpenProperty, false);
}
private void TextBox_KeyDown(object? sender, KeyEventArgs e)
@@ -627,7 +622,7 @@ namespace Avalonia.Controls
if (_textBox != null)
{
_suspendTextChangeHandler = true;
- Text = _textBox.Text;
+ SetCurrentValue(TextProperty, _textBox.Text);
_suspendTextChangeHandler = false;
}
}
@@ -660,7 +655,7 @@ namespace Avalonia.Controls
private void PopUp_Closed(object? sender, EventArgs e)
{
- IsDropDownOpen = false;
+ SetCurrentValue(IsDropDownOpenProperty, false);
if(!_isPopupClosing)
{
@@ -678,12 +673,12 @@ namespace Avalonia.Controls
if (IsDropDownOpen)
{
Focus();
- IsDropDownOpen = false;
+ SetCurrentValue(IsDropDownOpenProperty, false);
}
else
{
SetSelectedDate();
- IsDropDownOpen = true;
+ SetCurrentValue(IsDropDownOpenProperty, true);
_calendar!.Focus();
}
}
@@ -821,14 +816,14 @@ namespace Avalonia.Controls
if (SelectedDate != d)
{
- SelectedDate = d;
+ SetCurrentValue(SelectedDateProperty, d);
}
}
else
{
if (SelectedDate != null)
{
- SelectedDate = null;
+ SetCurrentValue(SelectedDateProperty, null);
}
}
}
@@ -838,7 +833,7 @@ namespace Avalonia.Controls
if (SelectedDate != d)
{
- SelectedDate = d;
+ SetCurrentValue(SelectedDateProperty, d);
}
}
}
@@ -884,7 +879,7 @@ namespace Avalonia.Controls
if (string.IsNullOrEmpty(Watermark) && !UseFloatingWatermark)
{
DateTimeFormatInfo dtfi = DateTimeHelper.GetCurrentDateFormat();
- Text = string.Empty;
+ SetCurrentValue(TextProperty, string.Empty);
_defaultText = string.Empty;
var watermarkFormat = "<{0}>";
string watermarkText;
diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs
index 17a6ad7a09..f6e4b32d6b 100644
--- a/src/Avalonia.Controls/ComboBox.cs
+++ b/src/Avalonia.Controls/ComboBox.cs
@@ -35,11 +35,8 @@ namespace Avalonia.Controls
///
/// Defines the property.
///
- public static readonly DirectProperty IsDropDownOpenProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(IsDropDownOpen),
- o => o.IsDropDownOpen,
- (o, v) => o.IsDropDownOpen = v);
+ public static readonly StyledProperty IsDropDownOpenProperty =
+ AvaloniaProperty.Register(nameof(IsDropDownOpen));
///
/// Defines the property.
@@ -77,7 +74,6 @@ namespace Avalonia.Controls
public static readonly StyledProperty VerticalContentAlignmentProperty =
ContentControl.VerticalContentAlignmentProperty.AddOwner();
- private bool _isDropDownOpen;
private Popup? _popup;
private object? _selectionBoxItem;
private readonly CompositeDisposable _subscriptionsOnOpen = new CompositeDisposable();
@@ -107,8 +103,8 @@ namespace Avalonia.Controls
///
public bool IsDropDownOpen
{
- get => _isDropDownOpen;
- set => SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value);
+ get => GetValue(IsDropDownOpenProperty);
+ set => SetValue(IsDropDownOpenProperty, value);
}
///
@@ -123,10 +119,10 @@ namespace Avalonia.Controls
///
/// Gets or sets the item to display as the control's content.
///
- protected object? SelectionBoxItem
+ public object? SelectionBoxItem
{
get => _selectionBoxItem;
- set => SetAndRaise(SelectionBoxItemProperty, ref _selectionBoxItem, value);
+ protected set => SetAndRaise(SelectionBoxItemProperty, ref _selectionBoxItem, value);
}
///
@@ -191,23 +187,23 @@ namespace Avalonia.Controls
if ((e.Key == Key.F4 && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) == false) ||
((e.Key == Key.Down || e.Key == Key.Up) && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt)))
{
- IsDropDownOpen = !IsDropDownOpen;
+ SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen);
e.Handled = true;
}
else if (IsDropDownOpen && e.Key == Key.Escape)
{
- IsDropDownOpen = false;
+ SetCurrentValue(IsDropDownOpenProperty, false);
e.Handled = true;
}
else if (!IsDropDownOpen && (e.Key == Key.Enter || e.Key == Key.Space))
{
- IsDropDownOpen = true;
+ SetCurrentValue(IsDropDownOpenProperty, true);
e.Handled = true;
}
else if (IsDropDownOpen && (e.Key == Key.Enter || e.Key == Key.Space))
{
SelectFocusedItem();
- IsDropDownOpen = false;
+ SetCurrentValue(IsDropDownOpenProperty, false);
e.Handled = true;
}
else if (!IsDropDownOpen)
@@ -291,7 +287,7 @@ namespace Avalonia.Controls
}
else
{
- IsDropDownOpen = !IsDropDownOpen;
+ SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen);
e.Handled = true;
}
}
@@ -390,7 +386,7 @@ namespace Avalonia.Controls
{
if (!isVisible && IsDropDownOpen)
{
- IsDropDownOpen = false;
+ SetCurrentValue(IsDropDownOpenProperty, false);
}
}
diff --git a/src/Avalonia.Controls/DateTimePickers/DatePicker.cs b/src/Avalonia.Controls/DateTimePickers/DatePicker.cs
index bb05cd1b1f..118183102a 100644
--- a/src/Avalonia.Controls/DateTimePickers/DatePicker.cs
+++ b/src/Avalonia.Controls/DateTimePickers/DatePicker.cs
@@ -1,7 +1,6 @@
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
-using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Interactivity;
using Avalonia.Layout;
@@ -29,65 +28,56 @@ namespace Avalonia.Controls
///
/// Define the Property
///
- public static readonly DirectProperty DayFormatProperty =
- AvaloniaProperty.RegisterDirect(nameof(DayFormat),
- x => x.DayFormat, (x, v) => x.DayFormat = v);
+ public static readonly StyledProperty DayFormatProperty =
+ AvaloniaProperty.Register(nameof(DayFormat), "%d");
///
/// Defines the Property
///
- public static readonly DirectProperty DayVisibleProperty =
- AvaloniaProperty.RegisterDirect(nameof(DayVisible),
- x => x.DayVisible, (x, v) => x.DayVisible = v);
+ public static readonly StyledProperty DayVisibleProperty =
+ AvaloniaProperty.Register(nameof(DayVisible), true);
///
/// Defines the Property
///
- public static readonly DirectProperty MaxYearProperty =
- AvaloniaProperty.RegisterDirect(nameof(MaxYear),
- x => x.MaxYear, (x, v) => x.MaxYear = v);
+ public static readonly StyledProperty MaxYearProperty =
+ AvaloniaProperty.Register(nameof(MaxYear), DateTimeOffset.MaxValue, coerce: CoerceMaxYear);
///
/// Defines the Property
///
- public static readonly DirectProperty MinYearProperty =
- AvaloniaProperty.RegisterDirect(nameof(MinYear),
- x => x.MinYear, (x, v) => x.MinYear = v);
+ public static readonly StyledProperty MinYearProperty =
+ AvaloniaProperty.Register(nameof(MinYear), DateTimeOffset.MinValue, coerce: CoerceMinYear);
///
/// Defines the Property
///
- public static readonly DirectProperty MonthFormatProperty =
- AvaloniaProperty.RegisterDirect(nameof(MonthFormat),
- x => x.MonthFormat, (x, v) => x.MonthFormat = v);
+ public static readonly StyledProperty MonthFormatProperty =
+ AvaloniaProperty.Register(nameof(MonthFormat), "MMMM");
///
/// Defines the Property
///
- public static readonly DirectProperty MonthVisibleProperty =
- AvaloniaProperty.RegisterDirect(nameof(MonthVisible),
- x => x.MonthVisible, (x, v) => x.MonthVisible = v);
+ public static readonly StyledProperty MonthVisibleProperty =
+ AvaloniaProperty.Register(nameof(MonthVisible), true);
///
/// Defines the Property
///
- public static readonly DirectProperty YearFormatProperty =
- AvaloniaProperty.RegisterDirect(nameof(YearFormat),
- x => x.YearFormat, (x, v) => x.YearFormat = v);
+ public static readonly StyledProperty YearFormatProperty =
+ AvaloniaProperty.Register(nameof(YearFormat), "yyyy");
///
/// Defines the Property
///
- public static readonly DirectProperty YearVisibleProperty =
- AvaloniaProperty.RegisterDirect(nameof(YearVisible),
- x => x.YearVisible, (x, v) => x.YearVisible = v);
+ public static readonly StyledProperty YearVisibleProperty =
+ AvaloniaProperty.Register(nameof(YearVisible), true);
///
/// Defines the Property
///
- public static readonly DirectProperty SelectedDateProperty =
- AvaloniaProperty.RegisterDirect(nameof(SelectedDate),
- x => x.SelectedDate, (x, v) => x.SelectedDate = v,
+ public static readonly StyledProperty SelectedDateProperty =
+ AvaloniaProperty.Register(nameof(SelectedDate),
defaultBindingMode: BindingMode.TwoWay);
// Template Items
@@ -103,28 +93,20 @@ namespace Avalonia.Controls
private bool _areControlsAvailable;
- private string _dayFormat = "%d";
- private bool _dayVisible = true;
- private DateTimeOffset _maxYear;
- private DateTimeOffset _minYear;
- private string _monthFormat = "MMMM";
- private bool _monthVisible = true;
- private string _yearFormat = "yyyy";
- private bool _yearVisible = true;
- private DateTimeOffset? _selectedDate;
-
public DatePicker()
{
PseudoClasses.Set(":hasnodate", true);
var now = DateTimeOffset.Now;
- _minYear = new DateTimeOffset(now.Date.Year - 100, 1, 1, 0, 0, 0, now.Offset);
- _maxYear = new DateTimeOffset(now.Date.Year + 100, 12, 31, 0, 0, 0, now.Offset);
+ SetCurrentValue(MinYearProperty, new DateTimeOffset(now.Date.Year - 100, 1, 1, 0, 0, 0, now.Offset));
+ SetCurrentValue(MaxYearProperty, new DateTimeOffset(now.Date.Year + 100, 12, 31, 0, 0, 0, now.Offset));
}
+ private static void OnGridVisibilityChanged(DatePicker sender, AvaloniaPropertyChangedEventArgs e) => sender.SetGrid();
+
public string DayFormat
{
- get => _dayFormat;
- set => SetAndRaise(DayFormatProperty, ref _dayFormat, value);
+ get => GetValue(DayFormatProperty);
+ set => SetValue(DayFormatProperty, value);
}
///
@@ -132,12 +114,8 @@ namespace Avalonia.Controls
///
public bool DayVisible
{
- get => _dayVisible;
- set
- {
- SetAndRaise(DayVisibleProperty, ref _dayVisible, value);
- SetGrid();
- }
+ get => GetValue(DayVisibleProperty);
+ set => SetValue(DayVisibleProperty, value);
}
///
@@ -145,16 +123,24 @@ namespace Avalonia.Controls
///
public DateTimeOffset MaxYear
{
- get => _maxYear;
- set
- {
- if (value < MinYear)
- throw new InvalidOperationException("MaxDate cannot be less than MinDate");
- SetAndRaise(MaxYearProperty, ref _maxYear, value);
+ get => GetValue(MaxYearProperty);
+ set => SetValue(MaxYearProperty, value);
+ }
- if (SelectedDate.HasValue && SelectedDate.Value > value)
- SelectedDate = value;
+ private static DateTimeOffset CoerceMaxYear(AvaloniaObject sender, DateTimeOffset value)
+ {
+ if (value < sender.GetValue(MinYearProperty))
+ {
+ throw new InvalidOperationException($"{MaxYearProperty.Name} cannot be less than {MinYearProperty.Name}");
}
+
+ return value;
+ }
+
+ private void OnMaxYearChanged(DateTimeOffset? value)
+ {
+ if (SelectedDate.HasValue && SelectedDate.Value > value)
+ SetCurrentValue(SelectedDateProperty, value);
}
///
@@ -162,16 +148,24 @@ namespace Avalonia.Controls
///
public DateTimeOffset MinYear
{
- get => _minYear;
- set
- {
- if (value > MaxYear)
- throw new InvalidOperationException("MinDate cannot be greater than MaxDate");
- SetAndRaise(MinYearProperty, ref _minYear, value);
+ get => GetValue(MinYearProperty);
+ set => SetValue(MinYearProperty, value);
+ }
- if (SelectedDate.HasValue && SelectedDate.Value < value)
- SelectedDate = value;
+ private static DateTimeOffset CoerceMinYear(AvaloniaObject sender, DateTimeOffset value)
+ {
+ if (value > sender.GetValue(MaxYearProperty))
+ {
+ throw new InvalidOperationException($"{MinYearProperty.Name} cannot be greater than {MaxYearProperty.Name}");
}
+
+ return value;
+ }
+
+ private void OnMinYearChanged(DateTimeOffset? value)
+ {
+ if (SelectedDate.HasValue && SelectedDate.Value < value)
+ SetCurrentValue(SelectedDateProperty, value);
}
///
@@ -179,8 +173,8 @@ namespace Avalonia.Controls
///
public string MonthFormat
{
- get => _monthFormat;
- set => SetAndRaise(MonthFormatProperty, ref _monthFormat, value);
+ get => GetValue(MonthFormatProperty);
+ set => SetValue(MonthFormatProperty, value);
}
///
@@ -188,12 +182,8 @@ namespace Avalonia.Controls
///
public bool MonthVisible
{
- get => _monthVisible;
- set
- {
- SetAndRaise(MonthVisibleProperty, ref _monthVisible, value);
- SetGrid();
- }
+ get => GetValue(MonthVisibleProperty);
+ set => SetValue(MonthVisibleProperty, value);
}
///
@@ -201,8 +191,8 @@ namespace Avalonia.Controls
///
public string YearFormat
{
- get => _yearFormat;
- set => SetAndRaise(YearFormatProperty, ref _yearFormat, value);
+ get => GetValue(YearFormatProperty);
+ set => SetValue(YearFormatProperty, value);
}
///
@@ -210,12 +200,8 @@ namespace Avalonia.Controls
///
public bool YearVisible
{
- get => _yearVisible;
- set
- {
- SetAndRaise(YearVisibleProperty, ref _yearVisible, value);
- SetGrid();
- }
+ get => GetValue(YearVisibleProperty);
+ set => SetValue(YearVisibleProperty, value);
}
///
@@ -223,14 +209,8 @@ namespace Avalonia.Controls
///
public DateTimeOffset? SelectedDate
{
- get => _selectedDate;
- set
- {
- var old = _selectedDate;
- SetAndRaise(SelectedDateProperty, ref _selectedDate, value);
- SetSelectedDateText();
- OnSelectedDateChanged(this, new DatePickerSelectedValueChangedEventArgs(old, value));
- }
+ get => GetValue(SelectedDateProperty);
+ set => SetValue(SelectedDateProperty, value);
}
///
@@ -287,6 +267,31 @@ namespace Avalonia.Controls
}
}
+ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
+ {
+ base.OnPropertyChanged(change);
+
+ if (change.Property == DayVisibleProperty || change.Property == MonthVisibleProperty || change.Property == YearVisibleProperty)
+ {
+ SetGrid();
+ }
+ else if (change.Property == MaxYearProperty)
+ {
+ OnMaxYearChanged(change.GetNewValue());
+ }
+ else if (change.Property == MinYearProperty)
+ {
+ OnMinYearChanged(change.GetNewValue());
+ }
+ else if (change.Property == SelectedDateProperty)
+ {
+ SetSelectedDateText();
+
+ var (oldValue, newValue) = change.GetOldAndNewValue();
+ OnSelectedDateChanged(this, new DatePickerSelectedValueChangedEventArgs(oldValue, newValue));
+ }
+ }
+
private void OnDismissPicker(object? sender, EventArgs e)
{
_popup!.Close();
@@ -296,7 +301,7 @@ namespace Avalonia.Controls
private void OnConfirmed(object? sender, EventArgs e)
{
_popup!.Close();
- SelectedDate = _presenter!.Date;
+ SetCurrentValue(SelectedDateProperty, _presenter!.Date);
}
private void SetGrid()
diff --git a/src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs b/src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs
index 2057480490..0ae743f30a 100644
--- a/src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs
+++ b/src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs
@@ -35,65 +35,72 @@ namespace Avalonia.Controls
///
/// Defines the Property
///
- public static readonly DirectProperty DateProperty =
- AvaloniaProperty.RegisterDirect(nameof(Date),
- x => x.Date, (x, v) => x.Date = v);
+ public static readonly StyledProperty DateProperty =
+ AvaloniaProperty.Register(nameof(Date), coerce: CoerceDate);
+
+ private static DateTimeOffset CoerceDate(AvaloniaObject sender, DateTimeOffset value)
+ {
+ var max = sender.GetValue(MaxYearProperty);
+ if (value > max)
+ {
+ return max;
+ }
+ var min = sender.GetValue(MinYearProperty);
+ if (value < min)
+ {
+ return min;
+ }
+
+ return value;
+ }
///
/// Defines the Property
///
- public static readonly DirectProperty DayFormatProperty =
- DatePicker.DayFormatProperty.AddOwner(x =>
- x.DayFormat, (x, v) => x.DayFormat = v);
+ public static readonly StyledProperty DayFormatProperty =
+ DatePicker.DayFormatProperty.AddOwner();
///
/// Defines the Property
///
- public static readonly DirectProperty DayVisibleProperty =
- DatePicker.DayVisibleProperty.AddOwner(x =>
- x.DayVisible, (x, v) => x.DayVisible = v);
+ public static readonly StyledProperty DayVisibleProperty =
+ DatePicker.DayVisibleProperty.AddOwner();
///
/// Defines the Property
///
- public static readonly DirectProperty MaxYearProperty =
- DatePicker.MaxYearProperty.AddOwner(x =>
- x.MaxYear, (x, v) => x.MaxYear = v);
+ public static readonly StyledProperty MaxYearProperty =
+ DatePicker.MaxYearProperty.AddOwner();
///
/// Defines the Property
///
- public static readonly DirectProperty MinYearProperty =
- DatePicker.MinYearProperty.AddOwner(x =>
- x.MinYear, (x, v) => x.MinYear = v);
+ public static readonly StyledProperty MinYearProperty =
+ DatePicker.MinYearProperty.AddOwner();
///
/// Defines the Property
///
- public static readonly DirectProperty MonthFormatProperty =
- DatePicker.MonthFormatProperty.AddOwner(x =>
- x.MonthFormat, (x, v) => x.MonthFormat = v);
+ public static readonly StyledProperty MonthFormatProperty =
+ DatePicker.MonthFormatProperty.AddOwner();
///
/// Defines the Property
///
- public static readonly DirectProperty MonthVisibleProperty =
- DatePicker.MonthVisibleProperty.AddOwner(x =>
- x.MonthVisible, (x, v) => x.MonthVisible = v);
+ public static readonly StyledProperty MonthVisibleProperty =
+ DatePicker.MonthVisibleProperty.AddOwner();
///
/// Defines the Property
///
- public static readonly DirectProperty YearFormatProperty =
- DatePicker.YearFormatProperty.AddOwner(x =>
- x.YearFormat, (x, v) => x.YearFormat = v);
+ public static readonly StyledProperty YearFormatProperty =
+ DatePicker.YearFormatProperty.AddOwner();
///
/// Defines the Property
///
- public static readonly DirectProperty YearVisibleProperty =
- DatePicker.YearVisibleProperty.AddOwner(x =>
- x.YearVisible, (x, v) => x.YearVisible = v);
+ public static readonly StyledProperty YearVisibleProperty =
+ DatePicker.YearVisibleProperty.AddOwner();
// Template Items
private Grid? _pickerContainer;
@@ -114,15 +121,6 @@ namespace Avalonia.Controls
private Button? _dayDownButton;
private Button? _yearDownButton;
- private DateTimeOffset _date;
- private string _dayFormat = "%d";
- private bool _dayVisible = true;
- private DateTimeOffset _maxYear;
- private DateTimeOffset _minYear;
- private string _monthFormat = "MMMM";
- private bool _monthVisible = true;
- private string _yearFormat = "yyyy";
- private bool _yearVisible = true;
private DateTimeOffset _syncDate;
private readonly GregorianCalendar _calendar;
@@ -131,11 +129,20 @@ namespace Avalonia.Controls
public DatePickerPresenter()
{
var now = DateTimeOffset.Now;
- _minYear = new DateTimeOffset(now.Year - 100, 1, 1, 0, 0, 0, now.Offset);
- _maxYear = new DateTimeOffset(now.Year + 100, 12, 31, 0, 0, 0, now.Offset);
- _date = now;
+ SetCurrentValue(MinYearProperty, new DateTimeOffset(now.Year - 100, 1, 1, 0, 0, 0, now.Offset));
+ SetCurrentValue(MaxYearProperty, new DateTimeOffset(now.Year + 100, 12, 31, 0, 0, 0, now.Offset));
+ SetCurrentValue(DateProperty, now);
_calendar = new GregorianCalendar();
- KeyboardNavigation.SetTabNavigation(this, KeyboardNavigationMode.Cycle);
+ }
+
+ static DatePickerPresenter()
+ {
+ KeyboardNavigation.TabNavigationProperty.OverrideDefaultValue(KeyboardNavigationMode.Cycle);
+ }
+
+ private static void OnDateRangeChanged(DatePickerPresenter sender, AvaloniaPropertyChangedEventArgs e)
+ {
+ sender.CoerceValue(DateProperty);
}
///
@@ -143,13 +150,14 @@ namespace Avalonia.Controls
///
public DateTimeOffset Date
{
- get => _date;
- set
- {
- SetAndRaise(DateProperty, ref _date, value);
- _syncDate = Date;
- InitPicker();
- }
+ get => GetValue(DateProperty);
+ set => SetValue(DateProperty, value);
+ }
+
+ private void OnDateChanged(DateTimeOffset newValue)
+ {
+ _syncDate = newValue;
+ InitPicker();
}
///
@@ -157,8 +165,8 @@ namespace Avalonia.Controls
///
public string DayFormat
{
- get => _dayFormat;
- set => SetAndRaise(DayFormatProperty, ref _dayFormat, value);
+ get => GetValue(DayFormatProperty);
+ set => SetValue(DayFormatProperty, value);
}
///
@@ -166,11 +174,8 @@ namespace Avalonia.Controls
///
public bool DayVisible
{
- get => _dayVisible;
- set
- {
- SetAndRaise(DayVisibleProperty, ref _dayVisible, value);
- }
+ get => GetValue(DayVisibleProperty);
+ set => SetValue(DayVisibleProperty, value);
}
///
@@ -178,16 +183,8 @@ namespace Avalonia.Controls
///
public DateTimeOffset MaxYear
{
- get => _maxYear;
- set
- {
- if (value < MinYear)
- throw new InvalidOperationException("MaxDate cannot be less than MinDate");
- SetAndRaise(MaxYearProperty, ref _maxYear, value);
-
- if (Date > value)
- Date = value;
- }
+ get => GetValue(MaxYearProperty);
+ set => SetValue(MaxYearProperty, value);
}
///
@@ -195,16 +192,8 @@ namespace Avalonia.Controls
///
public DateTimeOffset MinYear
{
- get => _minYear;
- set
- {
- if (value > MaxYear)
- throw new InvalidOperationException("MinDate cannot be greater than MaxDate");
- SetAndRaise(MinYearProperty, ref _minYear, value);
-
- if (Date < value)
- Date = value;
- }
+ get => GetValue(MinYearProperty);
+ set => SetValue(MinYearProperty, value);
}
///
@@ -212,8 +201,8 @@ namespace Avalonia.Controls
///
public string MonthFormat
{
- get => _monthFormat;
- set => SetAndRaise(MonthFormatProperty, ref _monthFormat, value);
+ get => GetValue(MonthFormatProperty);
+ set => SetValue(MonthFormatProperty, value);
}
///
@@ -221,11 +210,8 @@ namespace Avalonia.Controls
///
public bool MonthVisible
{
- get => _monthVisible;
- set
- {
- SetAndRaise(MonthVisibleProperty, ref _monthVisible, value);
- }
+ get => GetValue(MonthVisibleProperty);
+ set => SetValue(MonthVisibleProperty, value);
}
///
@@ -233,8 +219,8 @@ namespace Avalonia.Controls
///
public string YearFormat
{
- get => _yearFormat;
- set => SetAndRaise(YearFormatProperty, ref _yearFormat, value);
+ get => GetValue(YearFormatProperty);
+ set => SetValue(YearFormatProperty, value);
}
///
@@ -242,11 +228,8 @@ namespace Avalonia.Controls
///
public bool YearVisible
{
- get => _yearVisible;
- set
- {
- SetAndRaise(YearVisibleProperty, ref _yearVisible, value);
- }
+ get => GetValue(YearVisibleProperty);
+ set => SetValue(YearVisibleProperty, value);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
@@ -317,6 +300,20 @@ namespace Avalonia.Controls
InitPicker();
}
+ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
+ {
+ base.OnPropertyChanged(change);
+
+ if (change.Property == DateProperty)
+ {
+ OnDateChanged(change.GetNewValue());
+ }
+ else if (change.Property == MaxYearProperty || change.Property == MinYearProperty)
+ {
+ OnDateRangeChanged(this, change);
+ }
+ }
+
protected override void OnKeyDown(KeyEventArgs e)
{
switch (e.Key)
@@ -334,7 +331,7 @@ namespace Avalonia.Controls
}
break;
case Key.Enter:
- Date = _syncDate;
+ SetCurrentValue(DateProperty, _syncDate);
OnConfirmed();
e.Handled = true;
break;
@@ -381,13 +378,13 @@ namespace Avalonia.Controls
_monthSelector.SelectedValue = dt.Month;
_monthSelector.FormatDate = dt.Date;
}
-
+
if (YearVisible)
{
_yearSelector.SelectedValue = dt.Year;
_yearSelector.FormatDate = dt.Date;
}
-
+
_suppressUpdateSelection = false;
SetInitialFocus();
@@ -471,7 +468,7 @@ namespace Avalonia.Controls
private void OnAcceptButtonClicked(object? sender, RoutedEventArgs e)
{
- Date = _syncDate;
+ SetCurrentValue(DateProperty, _syncDate);
OnConfirmed();
}
diff --git a/src/Avalonia.Controls/DateTimePickers/TimePicker.cs b/src/Avalonia.Controls/DateTimePickers/TimePicker.cs
index a7a6881fe5..2f49a44b8c 100644
--- a/src/Avalonia.Controls/DateTimePickers/TimePicker.cs
+++ b/src/Avalonia.Controls/DateTimePickers/TimePicker.cs
@@ -1,7 +1,6 @@
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
-using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Layout;
using System;
@@ -30,23 +29,20 @@ namespace Avalonia.Controls
///
/// Defines the property
///
- public static readonly DirectProperty MinuteIncrementProperty =
- AvaloniaProperty.RegisterDirect(nameof(MinuteIncrement),
- x => x.MinuteIncrement, (x, v) => x.MinuteIncrement = v);
+ public static readonly StyledProperty MinuteIncrementProperty =
+ AvaloniaProperty.Register(nameof(MinuteIncrement), 1, coerce: CoerceMinuteIncrement);
///
/// Defines the property
///
- public static readonly DirectProperty ClockIdentifierProperty =
- AvaloniaProperty.RegisterDirect(nameof(ClockIdentifier),
- x => x.ClockIdentifier, (x, v) => x.ClockIdentifier = v);
+ public static readonly StyledProperty ClockIdentifierProperty =
+ AvaloniaProperty.Register(nameof(ClockIdentifier), "12HourClock", coerce: CoerceClockIdentifier);
///
/// Defines the property
///
- public static readonly DirectProperty SelectedTimeProperty =
- AvaloniaProperty.RegisterDirect(nameof(SelectedTime),
- x => x.SelectedTime, (x, v) => x.SelectedTime = v,
+ public static readonly StyledProperty SelectedTimeProperty =
+ AvaloniaProperty.Register(nameof(SelectedTime),
defaultBindingMode: BindingMode.TwoWay);
// Template Items
@@ -63,17 +59,13 @@ namespace Avalonia.Controls
private Grid? _contentGrid;
private Popup? _popup;
- private TimeSpan? _selectedTime;
- private int _minuteIncrement = 1;
- private string _clockIdentifier = "12HourClock";
-
public TimePicker()
{
PseudoClasses.Set(":hasnotime", true);
var timePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;
if (timePattern.IndexOf("H") != -1)
- _clockIdentifier = "24HourClock";
+ SetCurrentValue(ClockIdentifierProperty, "24HourClock");
}
///
@@ -81,14 +73,16 @@ namespace Avalonia.Controls
///
public int MinuteIncrement
{
- get => _minuteIncrement;
- set
- {
- if (value < 1 || value > 59)
- throw new ArgumentOutOfRangeException("1 >= MinuteIncrement <= 59");
- SetAndRaise(MinuteIncrementProperty, ref _minuteIncrement, value);
- SetSelectedTimeText();
- }
+ get => GetValue(MinuteIncrementProperty);
+ set => SetValue(MinuteIncrementProperty, value);
+ }
+
+ private static int CoerceMinuteIncrement(AvaloniaObject sender, int value)
+ {
+ if (value < 1 || value > 59)
+ throw new ArgumentOutOfRangeException(null, "1 >= MinuteIncrement <= 59");
+
+ return value;
}
///
@@ -96,15 +90,17 @@ namespace Avalonia.Controls
///
public string ClockIdentifier
{
- get => _clockIdentifier;
- set
- {
- if (!(string.IsNullOrEmpty(value) || value == "12HourClock" || value == "24HourClock"))
- throw new ArgumentException("Invalid ClockIdentifier");
- SetAndRaise(ClockIdentifierProperty, ref _clockIdentifier, value);
- SetGrid();
- SetSelectedTimeText();
- }
+
+ get => GetValue(ClockIdentifierProperty);
+ set => SetValue(ClockIdentifierProperty, value);
+ }
+
+ private static string CoerceClockIdentifier(AvaloniaObject sender, string value)
+ {
+ if (!(string.IsNullOrEmpty(value) || value == "12HourClock" || value == "24HourClock"))
+ throw new ArgumentException("Invalid ClockIdentifier", default(string));
+
+ return value;
}
///
@@ -112,14 +108,8 @@ namespace Avalonia.Controls
///
public TimeSpan? SelectedTime
{
- get => _selectedTime;
- set
- {
- var old = _selectedTime;
- SetAndRaise(SelectedTimeProperty, ref _selectedTime, value);
- OnSelectedTimeChanged(old, value);
- SetSelectedTimeText();
- }
+ get => GetValue(SelectedTimeProperty);
+ set => SetValue(SelectedTimeProperty, value);
}
///
@@ -173,6 +163,27 @@ namespace Avalonia.Controls
}
}
+ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
+ {
+ base.OnPropertyChanged(change);
+
+ if (change.Property == MinuteIncrementProperty)
+ {
+ SetSelectedTimeText();
+ }
+ else if (change.Property == ClockIdentifierProperty)
+ {
+ SetGrid();
+ SetSelectedTimeText();
+ }
+ else if (change.Property == SelectedTimeProperty)
+ {
+ var (oldValue, newValue) = change.GetOldAndNewValue();
+ OnSelectedTimeChanged(oldValue, newValue);
+ SetSelectedTimeText();
+ }
+ }
+
private void SetGrid()
{
if (_contentGrid == null)
@@ -270,7 +281,7 @@ namespace Avalonia.Controls
private void OnConfirmed(object? sender, EventArgs e)
{
_popup!.Close();
- SelectedTime = _presenter!.Time;
+ SetCurrentValue(SelectedTimeProperty, _presenter!.Time);
}
}
}
diff --git a/src/Avalonia.Controls/DateTimePickers/TimePickerPresenter.cs b/src/Avalonia.Controls/DateTimePickers/TimePickerPresenter.cs
index d6599c9f18..ba06e1b5e6 100644
--- a/src/Avalonia.Controls/DateTimePickers/TimePickerPresenter.cs
+++ b/src/Avalonia.Controls/DateTimePickers/TimePickerPresenter.cs
@@ -30,28 +30,29 @@ namespace Avalonia.Controls
///
/// Defines the property
///
- public static readonly DirectProperty MinuteIncrementProperty =
- TimePicker.MinuteIncrementProperty.AddOwner(x => x.MinuteIncrement,
- (x, v) => x.MinuteIncrement = v);
+ public static readonly StyledProperty MinuteIncrementProperty =
+ TimePicker.MinuteIncrementProperty.AddOwner();
///
/// Defines the property
///
- public static readonly DirectProperty ClockIdentifierProperty =
- TimePicker.ClockIdentifierProperty.AddOwner(x => x.ClockIdentifier,
- (x, v) => x.ClockIdentifier = v);
+ public static readonly StyledProperty ClockIdentifierProperty =
+ TimePicker.ClockIdentifierProperty.AddOwner();
///
/// Defines the property
///
- public static readonly DirectProperty TimeProperty =
- AvaloniaProperty.RegisterDirect(nameof(Time),
- x => x.Time, (x, v) => x.Time = v);
+ public static readonly StyledProperty TimeProperty =
+ AvaloniaProperty.Register(nameof(Time));
public TimePickerPresenter()
{
- Time = DateTime.Now.TimeOfDay;
- KeyboardNavigation.SetTabNavigation(this, KeyboardNavigationMode.Cycle);
+ SetCurrentValue(TimeProperty, DateTime.Now.TimeOfDay);
+ }
+
+ static TimePickerPresenter()
+ {
+ KeyboardNavigation.TabNavigationProperty.OverrideDefaultValue(KeyboardNavigationMode.Cycle);
}
// TemplateItems
@@ -70,24 +71,13 @@ namespace Avalonia.Controls
private Button? _minuteDownButton;
private Button? _periodDownButton;
- // Backing Fields
- private TimeSpan _time;
- private int _minuteIncrement = 1;
- private string _clockIdentifier = "12HourClock";
-
///
/// Gets or sets the minute increment in the selector
///
public int MinuteIncrement
{
- get => _minuteIncrement;
- set
- {
- if (value < 1 || value > 59)
- throw new ArgumentOutOfRangeException("1 >= MinuteIncrement <= 59");
- SetAndRaise(MinuteIncrementProperty, ref _minuteIncrement, value);
- InitPicker();
- }
+ get => GetValue(MinuteIncrementProperty);
+ set => SetValue(MinuteIncrementProperty, value);
}
///
@@ -95,14 +85,8 @@ namespace Avalonia.Controls
///
public string ClockIdentifier
{
- get => _clockIdentifier;
- set
- {
- if (string.IsNullOrEmpty(value) || !(value == "12HourClock" || value == "24HourClock"))
- throw new ArgumentException("Invalid ClockIdentifier");
- SetAndRaise(ClockIdentifierProperty, ref _clockIdentifier, value);
- InitPicker();
- }
+ get => GetValue(ClockIdentifierProperty);
+ set => SetValue(ClockIdentifierProperty, value);
}
///
@@ -110,12 +94,8 @@ namespace Avalonia.Controls
///
public TimeSpan Time
{
- get => _time;
- set
- {
- SetAndRaise(TimeProperty, ref _time, value);
- InitPicker();
- }
+ get => GetValue(TimeProperty);
+ set => SetValue(TimeProperty, value);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
@@ -162,6 +142,16 @@ namespace Avalonia.Controls
InitPicker();
}
+ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
+ {
+ base.OnPropertyChanged(change);
+
+ if (change.Property == MinuteIncrementProperty || change.Property == ClockIdentifierProperty || change.Property == TimeProperty)
+ {
+ InitPicker();
+ }
+ }
+
protected override void OnKeyDown(KeyEventArgs e)
{
switch (e.Key)
@@ -197,7 +187,7 @@ namespace Avalonia.Controls
hr = per == 1 ? (hr == 12) ? 12 : hr + 12 : per == 0 && hr == 12 ? 0 : hr;
}
- Time = new TimeSpan(hr, min, 0);
+ SetCurrentValue(TimeProperty, new TimeSpan(hr, min, 0));
base.OnConfirmed();
}
diff --git a/src/Avalonia.Controls/Documents/InlineCollection.cs b/src/Avalonia.Controls/Documents/InlineCollection.cs
index 12a096b105..fe9f5e64a8 100644
--- a/src/Avalonia.Controls/Documents/InlineCollection.cs
+++ b/src/Avalonia.Controls/Documents/InlineCollection.cs
@@ -24,7 +24,7 @@ namespace Avalonia.Controls.Documents
this.ForEachItem(
x =>
- {
+ {
x.InlineHost = InlineHost;
LogicalChildren?.Add(x);
Invalidate();
@@ -92,10 +92,10 @@ namespace Avalonia.Controls.Documents
public override void Add(Inline inline)
{
if (InlineHost is TextBlock textBlock && !string.IsNullOrEmpty(textBlock._text))
- {
+ {
base.Add(new Run(textBlock._text));
- textBlock._text = null;
+ textBlock._text = null;
}
base.Add(inline);
@@ -159,7 +159,7 @@ namespace Avalonia.Controls.Documents
oldParent.Remove(child);
}
- if(newParent != null)
+ if (newParent != null)
{
newParent.Add(child);
}
diff --git a/src/Avalonia.Controls/Flyouts/FlyoutBase.cs b/src/Avalonia.Controls/Flyouts/FlyoutBase.cs
index 9d4abec549..36f8371702 100644
--- a/src/Avalonia.Controls/Flyouts/FlyoutBase.cs
+++ b/src/Avalonia.Controls/Flyouts/FlyoutBase.cs
@@ -35,17 +35,14 @@ namespace Avalonia.Controls.Primitives
///
/// Defines the property
///
- public static readonly DirectProperty ShowModeProperty =
- AvaloniaProperty.RegisterDirect(nameof(ShowMode),
- x => x.ShowMode, (x, v) => x.ShowMode = v);
+ public static readonly StyledProperty ShowModeProperty =
+ AvaloniaProperty.Register(nameof(ShowMode));
///
/// Defines the property
///
- public static readonly DirectProperty OverlayInputPassThroughElementProperty =
- Popup.OverlayInputPassThroughElementProperty.AddOwner(
- o => o._overlayInputPassThroughElement,
- (o, v) => o._overlayInputPassThroughElement = v);
+ public static readonly StyledProperty OverlayInputPassThroughElementProperty =
+ Popup.OverlayInputPassThroughElementProperty.AddOwner();
///
/// Defines the AttachedFlyout property
@@ -56,12 +53,10 @@ namespace Avalonia.Controls.Primitives
private readonly Lazy _popupLazy;
private bool _isOpen;
private Control? _target;
- private FlyoutShowMode _showMode = FlyoutShowMode.Standard;
private Rect? _enlargedPopupRect;
private PixelRect? _enlargePopupRectScreenPixelRect;
private IDisposable? _transientDisposable;
private Action? _popupHostChangedHandler;
- private IInputElement? _overlayInputPassThroughElement;
static FlyoutBase()
{
@@ -98,8 +93,8 @@ namespace Avalonia.Controls.Primitives
///
public FlyoutShowMode ShowMode
{
- get => _showMode;
- set => SetAndRaise(ShowModeProperty, ref _showMode, value);
+ get => GetValue(ShowModeProperty);
+ set => SetValue(ShowModeProperty, value);
}
///
@@ -117,8 +112,8 @@ namespace Avalonia.Controls.Primitives
///
public IInputElement? OverlayInputPassThroughElement
{
- get => _overlayInputPassThroughElement;
- set => SetAndRaise(OverlayInputPassThroughElementProperty, ref _overlayInputPassThroughElement, value);
+ get => GetValue(OverlayInputPassThroughElementProperty);
+ set => SetValue(OverlayInputPassThroughElementProperty, value);
}
IPopupHost? IPopupHostProvider.PopupHost => Popup?.Host;
@@ -244,7 +239,7 @@ namespace Avalonia.Controls.Primitives
{
Popup.PlacementTarget = Target = placementTarget;
((ISetLogicalParent)Popup).SetParent(placementTarget);
- Popup.SetValue(StyledElement.TemplatedParentProperty, placementTarget.TemplatedParent);
+ Popup.TemplatedParent = placementTarget.TemplatedParent;
}
if (Popup.Child == null)
diff --git a/src/Avalonia.Controls/Label.cs b/src/Avalonia.Controls/Label.cs
index 5c8a6e0a5b..487d816204 100644
--- a/src/Avalonia.Controls/Label.cs
+++ b/src/Avalonia.Controls/Label.cs
@@ -1,11 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Text;
-using Avalonia.Controls.Primitives;
-using Avalonia.Controls.Templates;
-using Avalonia.Data;
-using Avalonia.Input;
+using Avalonia.Input;
using Avalonia.Interactivity;
namespace Avalonia.Controls
@@ -18,13 +11,8 @@ namespace Avalonia.Controls
///
/// Defines the Direct property
///
- public static readonly DirectProperty