From 10d41eaeee6bf2ae9822905c45746a9ef0730643 Mon Sep 17 00:00:00 2001 From: robloo Date: Sun, 19 Mar 2023 18:00:31 -0400 Subject: [PATCH 1/4] Switch AutoCompleteBox to using StyledProperty where possible --- .../AutoCompleteBox.Properties.cs | 104 ++++++++---------- .../AutoCompleteBox/AutoCompleteBox.cs | 65 +++++------ 2 files changed, 75 insertions(+), 94 deletions(-) diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs index 93b057e176..b38151854b 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.Properties.cs @@ -52,34 +52,32 @@ namespace Avalonia.Controls /// /// The identifier for the property. public static readonly StyledProperty IsTextCompletionEnabledProperty = - AvaloniaProperty.Register(nameof(IsTextCompletionEnabled)); + AvaloniaProperty.Register( + nameof(IsTextCompletionEnabled)); /// /// Identifies the property. /// /// The identifier for the property. public static readonly StyledProperty ItemTemplateProperty = - AvaloniaProperty.Register(nameof(ItemTemplate)); + AvaloniaProperty.Register( + nameof(ItemTemplate)); /// /// Identifies the property. /// /// The identifier for 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)); /// /// Identifies the property. /// /// The identifier the property. - public static readonly DirectProperty SelectedItemProperty = - AvaloniaProperty.RegisterDirect( + public static readonly StyledProperty SelectedItemProperty = + AvaloniaProperty.Register( nameof(SelectedItem), - o => o.SelectedItem, - (o, v) => o.SelectedItem = v, defaultBindingMode: BindingMode.TwoWay, enableDataValidation: true); @@ -115,58 +113,50 @@ namespace Avalonia.Controls /// Identifies the property. /// /// The identifier for the property. - public static readonly DirectProperty?> ItemFilterProperty = - AvaloniaProperty.RegisterDirect?>( - nameof(ItemFilter), - o => o.ItemFilter, - (o, v) => o.ItemFilter = v); + public static readonly StyledProperty?> ItemFilterProperty = + AvaloniaProperty.Register?>( + nameof(ItemFilter)); /// /// Identifies the property. /// /// The identifier for the property. - public static readonly DirectProperty?> TextFilterProperty = - AvaloniaProperty.RegisterDirect?>( + public static readonly StyledProperty?> TextFilterProperty = + AvaloniaProperty.Register?>( nameof(TextFilter), - o => o.TextFilter, - (o, v) => o.TextFilter = v, - unsetValue: AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.StartsWith)); + defaultValue: AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.StartsWith)); /// /// Identifies the property. /// /// The identifier for the property. - public static readonly DirectProperty?> ItemSelectorProperty = - AvaloniaProperty.RegisterDirect?>( - nameof(ItemSelector), - o => o.ItemSelector, - (o, v) => o.ItemSelector = v); + public static readonly StyledProperty?> ItemSelectorProperty = + AvaloniaProperty.Register?>( + nameof(ItemSelector)); /// /// Identifies the property. /// /// The identifier for the property. - public static readonly DirectProperty?> TextSelectorProperty = - AvaloniaProperty.RegisterDirect?>( - nameof(TextSelector), - o => o.TextSelector, - (o, v) => o.TextSelector = v); + public static readonly StyledProperty?> TextSelectorProperty = + AvaloniaProperty.Register?>( + nameof(TextSelector)); /// /// Identifies the property. /// /// The identifier for the property. - public static readonly DirectProperty ItemsProperty = - AvaloniaProperty.RegisterDirect( - nameof(Items), - o => o.Items, - (o, v) => o.Items = v); + public static readonly StyledProperty ItemsProperty = + AvaloniaProperty.Register( + nameof(Items)); - public static readonly DirectProperty>>?> AsyncPopulatorProperty = - AvaloniaProperty.RegisterDirect>>?>( - nameof(AsyncPopulator), - o => o.AsyncPopulator, - (o, v) => o.AsyncPopulator = v); + /// + /// Identifies the property. + /// + /// The identifier for the property. + public static readonly StyledProperty>>?> AsyncPopulatorProperty = + AvaloniaProperty.Register>>?>( + nameof(AsyncPopulator)); /// /// Gets or sets the minimum number of characters required to be entered @@ -265,8 +255,8 @@ namespace Avalonia.Controls /// public bool IsDropDownOpen { - get => _isDropDownOpen; - set => SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value); + get => GetValue(IsDropDownOpenProperty); + set => SetValue(IsDropDownOpenProperty, value); } /// @@ -303,8 +293,8 @@ namespace Avalonia.Controls /// public object? SelectedItem { - get => _selectedItem; - set => SetAndRaise(SelectedItemProperty, ref _selectedItem, value); + get => GetValue(SelectedItemProperty); + set => SetValue(SelectedItemProperty, value); } /// @@ -388,8 +378,8 @@ namespace Avalonia.Controls /// public AutoCompleteFilterPredicate? ItemFilter { - get => _itemFilter; - set => SetAndRaise(ItemFilterProperty, ref _itemFilter, value); + get => GetValue(ItemFilterProperty); + set => SetValue(ItemFilterProperty, value); } /// @@ -406,8 +396,8 @@ namespace Avalonia.Controls /// public AutoCompleteFilterPredicate? TextFilter { - get => _textFilter; - set => SetAndRaise(TextFilterProperty, ref _textFilter, value); + get => GetValue(TextFilterProperty); + set => SetValue(TextFilterProperty, value); } /// @@ -420,8 +410,8 @@ namespace Avalonia.Controls /// public AutoCompleteSelector? ItemSelector { - get => _itemSelector; - set => SetAndRaise(ItemSelectorProperty, ref _itemSelector, value); + get => GetValue(ItemSelectorProperty); + set => SetValue(ItemSelectorProperty, value); } /// @@ -436,14 +426,14 @@ namespace Avalonia.Controls /// public AutoCompleteSelector? TextSelector { - get => _textSelector; - set => SetAndRaise(TextSelectorProperty, ref _textSelector, value); + get => GetValue(TextSelectorProperty); + set => SetValue(TextSelectorProperty, value); } public Func>>? AsyncPopulator { - get => _asyncPopulator; - set => SetAndRaise(AsyncPopulatorProperty, ref _asyncPopulator, value); + get => GetValue(AsyncPopulatorProperty); + set => SetValue(AsyncPopulatorProperty, value); } /// @@ -454,8 +444,8 @@ namespace Avalonia.Controls /// drop-down portion of the control. public IEnumerable? Items { - get => _itemsEnumerable; - set => SetAndRaise(ItemsProperty, ref _itemsEnumerable, value); + get => GetValue(ItemsProperty); + set => SetValue(ItemsProperty, value); } } } diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs index 2d074ef7fa..72a23144cf 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs @@ -94,8 +94,6 @@ namespace Avalonia.Controls /// private const string ElementTextBox = "PART_TextBox"; - private IEnumerable? _itemsEnumerable; - /// /// Gets or sets a local cached copy of the items data. /// @@ -188,24 +186,15 @@ namespace Avalonia.Controls /// private IDisposable? _collectionChangeSubscription; - private Func>>? _asyncPopulator; private CancellationTokenSource? _populationCancellationTokenSource; private bool _itemTemplateIsFromValueMemberBinding = true; private bool _settingItemTemplateFromValueMemberBinding; - private object? _selectedItem; - private bool _isDropDownOpen; private bool _isFocused = false; private string? _searchText = string.Empty; - private AutoCompleteFilterPredicate? _itemFilter; - private AutoCompleteFilterPredicate? _textFilter = AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.StartsWith); - - private AutoCompleteSelector? _itemSelector; - private AutoCompleteSelector? _textSelector; - private readonly EventHandler _populateDropDownHandler; /// @@ -264,7 +253,7 @@ namespace Avalonia.Controls bool isEnabled = (bool)e.NewValue!; if (!isEnabled) { - IsDropDownOpen = false; + SetCurrentValue(IsDropDownOpenProperty, false); } } @@ -388,7 +377,7 @@ namespace Avalonia.Controls { // Reset the old value before it was incorrectly written _ignorePropertyChange = true; - SetValue(e.Property, e.OldValue); + SetCurrentValue(e.Property, e.OldValue); throw new InvalidOperationException("Cannot set read-only property SearchText."); } @@ -403,7 +392,7 @@ namespace Avalonia.Controls AutoCompleteFilterMode mode = (AutoCompleteFilterMode)e.NewValue!; // Sets the filter predicate for the new value - TextFilter = AutoCompleteSearch.GetFilter(mode); + SetCurrentValue(TextFilterProperty, AutoCompleteSearch.GetFilter(mode)); } /// @@ -417,12 +406,12 @@ namespace Avalonia.Controls // If null, revert to the "None" predicate if (value == null) { - FilterMode = AutoCompleteFilterMode.None; + SetCurrentValue(FilterModeProperty, AutoCompleteFilterMode.None); } else { - FilterMode = AutoCompleteFilterMode.Custom; - TextFilter = null; + SetCurrentValue(FilterModeProperty, AutoCompleteFilterMode.Custom); + SetCurrentValue(TextFilterProperty, null); } } @@ -442,7 +431,7 @@ namespace Avalonia.Controls } private void OnValueMemberBindingChanged(IBinding? value) { - if(_itemTemplateIsFromValueMemberBinding) + if (_itemTemplateIsFromValueMemberBinding) { var template = new FuncDataTemplate( @@ -456,7 +445,7 @@ namespace Avalonia.Controls }); _settingItemTemplateFromValueMemberBinding = true; - ItemTemplate = template; + SetCurrentValue(ItemTemplateProperty, template); _settingItemTemplateFromValueMemberBinding = false; } } @@ -713,7 +702,7 @@ namespace Avalonia.Controls // The drop down is not open, the Down key will toggle it open. if (e.Key == Key.Down) { - IsDropDownOpen = true; + SetCurrentValue(IsDropDownOpenProperty, true); e.Handled = true; } } @@ -722,7 +711,7 @@ namespace Avalonia.Controls switch (e.Key) { case Key.F4: - IsDropDownOpen = !IsDropDownOpen; + SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen); e.Handled = true; break; @@ -827,7 +816,7 @@ namespace Avalonia.Controls } else { - IsDropDownOpen = false; + SetCurrentValue(IsDropDownOpenProperty, false); _userCalledPopulate = false; ClearTextBoxSelection(); } @@ -1021,7 +1010,7 @@ namespace Avalonia.Controls if (args.Cancel) { _ignorePropertyChange = true; - SetValue(IsDropDownOpenProperty, oldValue); + SetCurrentValue(IsDropDownOpenProperty, oldValue); } else { @@ -1046,7 +1035,7 @@ namespace Avalonia.Controls if (args.Cancel) { _ignorePropertyChange = true; - SetValue(IsDropDownOpenProperty, oldValue); + SetCurrentValue(IsDropDownOpenProperty, oldValue); } else { @@ -1066,7 +1055,7 @@ namespace Avalonia.Controls // Force the drop down dependency property to be false. if (IsDropDownOpen) { - IsDropDownOpen = false; + SetCurrentValue(IsDropDownOpenProperty, false); } // Fire the DropDownClosed event @@ -1088,7 +1077,7 @@ namespace Avalonia.Controls // Update the prefix/search text. SearchText = Text; - if(TryPopulateAsync(SearchText)) + if (TryPopulateAsync(SearchText)) { return; } @@ -1110,7 +1099,7 @@ namespace Avalonia.Controls _populationCancellationTokenSource?.Dispose(); _populationCancellationTokenSource = null; - if(_asyncPopulator == null) + if (AsyncPopulator == null) { return false; } @@ -1127,7 +1116,7 @@ namespace Avalonia.Controls try { - IEnumerable result = await _asyncPopulator!.Invoke(searchText, cancellationToken); + IEnumerable result = await AsyncPopulator!.Invoke(searchText, cancellationToken); var resultList = result.ToList(); if (cancellationToken.IsCancellationRequested) @@ -1139,7 +1128,7 @@ namespace Avalonia.Controls { if (!cancellationToken.IsCancellationRequested) { - Items = resultList; + SetCurrentValue(ItemsProperty, resultList); PopulateComplete(); } }); @@ -1199,7 +1188,7 @@ namespace Avalonia.Controls private string? FormatValue(object? value, bool clearDataContext) { string? result = FormatValue(value); - if(clearDataContext && _valueBindingEvaluator != null) + if (clearDataContext && _valueBindingEvaluator != null) { _valueBindingEvaluator.ClearDataContext(); } @@ -1332,7 +1321,7 @@ namespace Avalonia.Controls // 1. Minimum prefix length // 2. If a delay timer is in use, use it bool populateReady = newText.Length >= MinimumPrefixLength && MinimumPrefixLength >= 0; - if(populateReady && MinimumPrefixLength == 0 && String.IsNullOrEmpty(newText) && String.IsNullOrEmpty(SearchText)) + if (populateReady && MinimumPrefixLength == 0 && String.IsNullOrEmpty(newText) && String.IsNullOrEmpty(SearchText)) { populateReady = false; } @@ -1361,10 +1350,12 @@ namespace Avalonia.Controls { _skipSelectedItemTextUpdate = true; } - SelectedItem = null; + + SetCurrentValue(SelectedItemProperty, null); + if (IsDropDownOpen) { - IsDropDownOpen = false; + SetCurrentValue(IsDropDownOpenProperty, false); } } } @@ -1600,7 +1591,7 @@ namespace Avalonia.Controls if (isDropDownOpen != IsDropDownOpen) { _ignorePropertyChange = true; - IsDropDownOpen = isDropDownOpen; + SetCurrentValue(IsDropDownOpenProperty, isDropDownOpen); } if (IsDropDownOpen) { @@ -1688,7 +1679,7 @@ namespace Avalonia.Controls { _skipSelectedItemTextUpdate = true; } - SelectedItem = newSelectedItem; + SetCurrentValue(SelectedItemProperty, newSelectedItem); // Restore updates for TextSelection if (_ignoreTextSelectionChange) @@ -1784,7 +1775,7 @@ namespace Avalonia.Controls /// The selection changed event data. private void OnAdapterSelectionChanged(object? sender, SelectionChangedEventArgs e) { - SelectedItem = _adapter!.SelectedItem; + SetCurrentValue(SelectedItemProperty, _adapter!.SelectedItem); } //TODO Check UpdateTextCompletion @@ -1795,7 +1786,7 @@ namespace Avalonia.Controls /// The event data. private void OnAdapterSelectionComplete(object? sender, RoutedEventArgs e) { - IsDropDownOpen = false; + SetCurrentValue(IsDropDownOpenProperty, false); // Completion will update the selected value //UpdateTextCompletion(false); From 46f38f42af8d21d89e4206d17efb72f93fa29516 Mon Sep 17 00:00:00 2001 From: robloo Date: Sun, 19 Mar 2023 18:03:00 -0400 Subject: [PATCH 2/4] Fix comments with incorrect property reference --- src/Avalonia.Base/Layout/Layoutable.cs | 2 +- src/Avalonia.Base/Visual.cs | 2 +- src/Avalonia.Controls.ItemsRepeater/Layout/UniformGridLayout.cs | 2 +- src/Avalonia.Controls/Primitives/ScrollBar.cs | 2 +- src/Avalonia.Controls/ScrollViewer.cs | 2 +- src/Avalonia.Controls/Slider.cs | 2 +- src/Avalonia.Controls/TopLevel.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Base/Layout/Layoutable.cs b/src/Avalonia.Base/Layout/Layoutable.cs index ea84dc84bd..ed88b73149 100644 --- a/src/Avalonia.Base/Layout/Layoutable.cs +++ b/src/Avalonia.Base/Layout/Layoutable.cs @@ -125,7 +125,7 @@ namespace Avalonia.Layout AvaloniaProperty.Register(nameof(VerticalAlignment)); /// - /// Defines the property. + /// Defines the property. /// public static readonly StyledProperty UseLayoutRoundingProperty = AvaloniaProperty.Register(nameof(UseLayoutRounding), defaultValue: true, inherits: true); diff --git a/src/Avalonia.Base/Visual.cs b/src/Avalonia.Base/Visual.cs index df0c5b100f..b4c5b2a1d2 100644 --- a/src/Avalonia.Base/Visual.cs +++ b/src/Avalonia.Base/Visual.cs @@ -50,7 +50,7 @@ namespace Avalonia AvaloniaProperty.Register(nameof(Clip)); /// - /// Defines the property. + /// Defines the property. /// public static readonly StyledProperty IsVisibleProperty = AvaloniaProperty.Register(nameof(IsVisible), true); diff --git a/src/Avalonia.Controls.ItemsRepeater/Layout/UniformGridLayout.cs b/src/Avalonia.Controls.ItemsRepeater/Layout/UniformGridLayout.cs index c539396e75..7701513455 100644 --- a/src/Avalonia.Controls.ItemsRepeater/Layout/UniformGridLayout.cs +++ b/src/Avalonia.Controls.ItemsRepeater/Layout/UniformGridLayout.cs @@ -113,7 +113,7 @@ namespace Avalonia.Layout AvaloniaProperty.Register(nameof(MinRowSpacing)); /// - /// Defines the property. + /// Defines the property. /// public static readonly StyledProperty MaximumRowsOrColumnsProperty = AvaloniaProperty.Register(nameof(MaximumRowsOrColumns)); diff --git a/src/Avalonia.Controls/Primitives/ScrollBar.cs b/src/Avalonia.Controls/Primitives/ScrollBar.cs index 8b2321e40b..b4a8408901 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBar.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBar.cs @@ -49,7 +49,7 @@ namespace Avalonia.Controls.Primitives AvaloniaProperty.Register(nameof(Orientation), Orientation.Vertical); /// - /// Defines the property. + /// Defines the property. /// public static readonly DirectProperty IsExpandedProperty = AvaloniaProperty.RegisterDirect( diff --git a/src/Avalonia.Controls/ScrollViewer.cs b/src/Avalonia.Controls/ScrollViewer.cs index af874bd380..0f1b8f388c 100644 --- a/src/Avalonia.Controls/ScrollViewer.cs +++ b/src/Avalonia.Controls/ScrollViewer.cs @@ -200,7 +200,7 @@ namespace Avalonia.Controls ScrollBarVisibility.Auto); /// - /// Defines the property. + /// Defines the property. /// public static readonly DirectProperty IsExpandedProperty = ScrollBar.IsExpandedProperty.AddOwner(o => o.IsExpanded); diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index 7de726a932..a9c9f42af8 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -80,7 +80,7 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(TickPlacement), 0d); /// - /// Defines the property. + /// Defines the property. /// public static readonly StyledProperty?> TicksProperty = TickBar.TicksProperty.AddOwner(); diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index dcf387afab..bf0de1d79f 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -75,7 +75,7 @@ namespace Avalonia.Controls unsetValue: WindowTransparencyLevel.None); /// - /// Defines the property. + /// Defines the property. /// public static readonly StyledProperty TransparencyBackgroundFallbackProperty = AvaloniaProperty.Register(nameof(TransparencyBackgroundFallback), Brushes.White); From 637f04ac3adb6b67e50934a9b1bc2f675c43ea01 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 22 Mar 2023 15:11:36 +0600 Subject: [PATCH 3/4] Make DispatcherPriority values more in line with WPF --- .../Threading/DispatcherPriority.cs | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/Avalonia.Base/Threading/DispatcherPriority.cs b/src/Avalonia.Base/Threading/DispatcherPriority.cs index 9d0b91f6f2..a4386370f0 100644 --- a/src/Avalonia.Base/Threading/DispatcherPriority.cs +++ b/src/Avalonia.Base/Threading/DispatcherPriority.cs @@ -16,64 +16,64 @@ namespace Avalonia.Threading { Value = value; } - - /// - /// Minimum possible priority that's actually dispatched, default value - /// - internal static readonly DispatcherPriority MinimumActiveValue = new(0); /// - /// A dispatcher priority for jobs that shouldn't be executed yet + /// The lowest foreground dispatcher priority /// - public static DispatcherPriority Inactive => new(MinimumActiveValue - 1); + internal static readonly DispatcherPriority Default = new(0); + /// - /// Minimum valid priority + /// The job will be processed with the same priority as input. /// - internal static readonly DispatcherPriority MinValue = new(Inactive); + public static readonly DispatcherPriority Input = new(Default - 1); /// - /// Used internally in dispatcher code + /// The job will be processed after other non-idle operations have completed. /// - public static DispatcherPriority Invalid => new(MinimumActiveValue - 2); + public static readonly DispatcherPriority Background = new(Input - 1); + /// + /// The job will be processed after background operations have completed. + /// + public static readonly DispatcherPriority ContextIdle = new(Background - 1); /// - /// The job will be processed when the system is idle. + /// The job will be processed when the application is idle. /// - [Obsolete("WPF compatibility")] public static readonly DispatcherPriority SystemIdle = MinimumActiveValue; - + public static readonly DispatcherPriority ApplicationIdle = new (ContextIdle - 1); + /// - /// The job will be processed when the application is idle. + /// The job will be processed when the system is idle. /// - [Obsolete("WPF compatibility")] public static readonly DispatcherPriority ApplicationIdle = new (SystemIdle + 1); + public static readonly DispatcherPriority SystemIdle = new(ApplicationIdle - 1); /// - /// The job will be processed after background operations have completed. + /// Minimum possible priority that's actually dispatched, default value /// - [Obsolete("WPF compatibility")] public static readonly DispatcherPriority ContextIdle = new(ApplicationIdle + 1); + internal static readonly DispatcherPriority MinimumActiveValue = new(SystemIdle); + /// - /// The job will be processed with normal priority. + /// A dispatcher priority for jobs that shouldn't be executed yet /// -#pragma warning disable CS0618 - public static readonly DispatcherPriority Normal = new(ContextIdle + 1); -#pragma warning restore CS0618 - + public static DispatcherPriority Inactive => new(MinimumActiveValue - 1); + /// - /// The job will be processed after other non-idle operations have completed. + /// Minimum valid priority /// - public static readonly DispatcherPriority Background = new(MinValue + 1); - + internal static readonly DispatcherPriority MinValue = new(Inactive); + /// - /// The job will be processed with the same priority as input. + /// Used internally in dispatcher code /// - public static readonly DispatcherPriority Input = new(Background + 1); - + public static DispatcherPriority Invalid => new(MinimumActiveValue - 2); + + /// /// The job will be processed after layout and render but before input. /// - public static readonly DispatcherPriority Loaded = new(Input + 1); + public static readonly DispatcherPriority Loaded = new(Default + 1); /// /// The job will be processed with the same priority as render. @@ -98,12 +98,19 @@ namespace Avalonia.Threading /// /// The job will be processed with the same priority as data binding. /// - [Obsolete("WPF compatibility")] public static readonly DispatcherPriority DataBind = MinValue; + [Obsolete("WPF compatibility")] public static readonly DispatcherPriority DataBind = new(Layout); + + /// + /// The job will be processed with normal priority. + /// +#pragma warning disable CS0618 + public static readonly DispatcherPriority Normal = new(DataBind + 1); +#pragma warning restore CS0618 /// /// The job will be processed before other asynchronous operations. /// - public static readonly DispatcherPriority Send = new(Layout + 1); + public static readonly DispatcherPriority Send = new(Normal + 1); /// /// Maximum possible priority From e3a75b869bba63fccec09062b8d7dcbcae44e34e Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 22 Mar 2023 15:23:56 +0600 Subject: [PATCH 4/4] QoL --- .../Threading/DispatcherPriority.cs | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Threading/DispatcherPriority.cs b/src/Avalonia.Base/Threading/DispatcherPriority.cs index a4386370f0..a71140d288 100644 --- a/src/Avalonia.Base/Threading/DispatcherPriority.cs +++ b/src/Avalonia.Base/Threading/DispatcherPriority.cs @@ -57,7 +57,7 @@ namespace Avalonia.Threading /// /// A dispatcher priority for jobs that shouldn't be executed yet /// - public static DispatcherPriority Inactive => new(MinimumActiveValue - 1); + public static readonly DispatcherPriority Inactive = new(MinimumActiveValue - 1); /// /// Minimum valid priority @@ -67,7 +67,7 @@ namespace Avalonia.Threading /// /// Used internally in dispatcher code /// - public static DispatcherPriority Invalid => new(MinimumActiveValue - 2); + public static readonly DispatcherPriority Invalid = new(MinimumActiveValue - 2); /// @@ -158,5 +158,42 @@ namespace Avalonia.Threading if (priority < Inactive || priority > MaxValue) throw new ArgumentException("Invalid DispatcherPriority value", parameterName); } + +#pragma warning disable CS0618 + public override string ToString() + { + if (this == Invalid) + return nameof(Invalid); + if (this == Inactive) + return nameof(Inactive); + if (this == SystemIdle) + return nameof(SystemIdle); + if (this == ContextIdle) + return nameof(ContextIdle); + if (this == ApplicationIdle) + return nameof(ApplicationIdle); + if (this == Background) + return nameof(Background); + if (this == Input) + return nameof(Input); + if (this == Default) + return nameof(Default); + if (this == Loaded) + return nameof(Loaded); + if (this == Render) + return nameof(Render); + if (this == Composition) + return nameof(Composition); + if (this == PreComposition) + return nameof(PreComposition); + if (this == DataBind) + return nameof(DataBind); + if (this == Normal) + return nameof(Normal); + if (this == Send) + return nameof(Send); + return Value.ToString(); + } +#pragma warning restore CS0618 } }