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/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); 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);