From ef74802035fbbc0aa5a96b3891a711e383578055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Mon, 16 May 2022 21:22:17 +0200 Subject: [PATCH 01/12] Add RequestBringIntoView property --- src/Avalonia.Controls/Control.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Control.cs b/src/Avalonia.Controls/Control.cs index d6a5fa0727..7011acc3da 100644 --- a/src/Avalonia.Controls/Control.cs +++ b/src/Avalonia.Controls/Control.cs @@ -53,7 +53,7 @@ namespace Avalonia.Controls /// Event raised when an element wishes to be scrolled into view. /// public static readonly RoutedEvent RequestBringIntoViewEvent = - RoutedEvent.Register("RequestBringIntoView", RoutingStrategies.Bubble); + RoutedEvent.Register(nameof(RequestBringIntoView), RoutingStrategies.Bubble); /// /// Provides event data for the event. @@ -126,6 +126,15 @@ namespace Avalonia.Controls set => SetValue(FlowDirectionProperty, value); } + /// + /// Occurs when an element wishes to be scrolled into view. + /// + public event EventHandler? RequestBringIntoView + { + add => AddHandler(RequestBringIntoViewEvent, value); + remove => RemoveHandler(RequestBringIntoViewEvent, value); + } + /// /// Occurs when the user has completed a context input gesture, such as a right-click. /// From 149a51e366e34d1caf93fc757ae6538ee8998f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Mon, 16 May 2022 21:22:39 +0200 Subject: [PATCH 02/12] Add IsSelectedChanged property --- .../Primitives/SelectingItemsControl.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index a730659330..6a3ac95fca 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -103,7 +103,7 @@ namespace Avalonia.Controls.Primitives /// public static readonly RoutedEvent IsSelectedChangedEvent = RoutedEvent.Register( - "IsSelectedChanged", + nameof(IsSelectedChanged), RoutingStrategies.Bubble); /// @@ -139,6 +139,17 @@ namespace Avalonia.Controls.Primitives IsSelectedChangedEvent.AddClassHandler((x, e) => x.ContainerSelectionChanged(e)); } + /// + /// Event that should be raised by items that implement to + /// notify the parent that their selection state + /// has changed. + /// + public event EventHandler? IsSelectedChanged + { + add { AddHandler(IsSelectedChangedEvent, value); } + remove { RemoveHandler(IsSelectedChangedEvent, value); } + } + /// /// Occurs when the control's selection changes. /// From f553c44c8416791603c65d9c675b34ddb320c964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Mon, 16 May 2022 21:22:46 +0200 Subject: [PATCH 03/12] Use nameof --- src/Avalonia.Controls/Primitives/SelectingItemsControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index 6a3ac95fca..e6d48ca149 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -111,7 +111,7 @@ namespace Avalonia.Controls.Primitives /// public static readonly RoutedEvent SelectionChangedEvent = RoutedEvent.Register( - "SelectionChanged", + nameof(SelectionChanged), RoutingStrategies.Bubble); /// From 6e2dea0fa0c7d4eab51f82990b8362a26439f3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Mon, 16 May 2022 21:23:05 +0200 Subject: [PATCH 04/12] Add WindowClosed and WindowOpened property --- src/Avalonia.Controls/Window.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index a5f99918b2..3a8a721eec 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -171,15 +171,14 @@ namespace Avalonia.Controls /// /// Routed event that can be used for global tracking of window destruction /// - public static readonly RoutedEvent WindowClosedEvent = - RoutedEvent.Register("WindowClosed", RoutingStrategies.Direct); + public static readonly RoutedEvent WindowClosedEvent = + RoutedEvent.Register(nameof(WindowClosed), RoutingStrategies.Direct); /// /// Routed event that can be used for global tracking of opening windows /// - public static readonly RoutedEvent WindowOpenedEvent = - RoutedEvent.Register("WindowOpened", RoutingStrategies.Direct); - + public static readonly RoutedEvent WindowOpenedEvent = + RoutedEvent.Register(nameof(WindowOpened), RoutingStrategies.Direct); private readonly NameScope _nameScope = new NameScope(); @@ -446,6 +445,24 @@ namespace Avalonia.Controls } } + /// + /// Routed event that can be used for global tracking of window destruction. + /// + public event EventHandler? WindowClosed + { + add => AddHandler(WindowClosedEvent, value); + remove => RemoveHandler(WindowClosedEvent, value); + } + + /// + /// Routed event that can be used for global tracking of opening windows. + /// + public event EventHandler? WindowOpened + { + add => AddHandler(WindowOpenedEvent, value); + remove => RemoveHandler(WindowOpenedEvent, value); + } + /// /// Starts moving a window with left button being held. Should be called from left mouse button press event handler /// From 6af332b7d057e74e0b9460a1d008639a33960992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Mon, 16 May 2022 21:27:33 +0200 Subject: [PATCH 05/12] Use nameof in RoutedEvent.Register --- src/Avalonia.Base/Input/InputElement.cs | 18 +++++++++--------- .../Primitives/TemplatedControl.cs | 2 +- src/Avalonia.Controls/TextBox.cs | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Avalonia.Base/Input/InputElement.cs b/src/Avalonia.Base/Input/InputElement.cs index d3c1b3f597..f4e25ebada 100644 --- a/src/Avalonia.Base/Input/InputElement.cs +++ b/src/Avalonia.Base/Input/InputElement.cs @@ -94,7 +94,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent KeyDownEvent = RoutedEvent.Register( - "KeyDown", + nameof(KeyDown), RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// @@ -102,7 +102,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent KeyUpEvent = RoutedEvent.Register( - "KeyUp", + nameof(KeyUp), RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// @@ -116,7 +116,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent TextInputEvent = RoutedEvent.Register( - "TextInput", + nameof(TextInput), RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// @@ -124,7 +124,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent TextInputMethodClientRequestedEvent = RoutedEvent.Register( - "TextInputMethodClientRequested", + nameof(TextInputMethodClientRequested), RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// @@ -144,7 +144,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent PointerMovedEvent = RoutedEvent.Register( - "PointerMoved", + nameof(PointerMoved), RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// @@ -152,7 +152,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent PointerPressedEvent = RoutedEvent.Register( - "PointerPressed", + nameof(PointerPressed), RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// @@ -160,7 +160,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent PointerReleasedEvent = RoutedEvent.Register( - "PointerReleased", + nameof(PointerReleased), RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// @@ -168,7 +168,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent PointerCaptureLostEvent = RoutedEvent.Register( - "PointerCaptureLost", + nameof(PointerCaptureLost), RoutingStrategies.Direct); /// @@ -176,7 +176,7 @@ namespace Avalonia.Input /// public static readonly RoutedEvent PointerWheelChangedEvent = RoutedEvent.Register( - "PointerWheelChanged", + nameof(PointerWheelChanged), RoutingStrategies.Tunnel | RoutingStrategies.Bubble); /// diff --git a/src/Avalonia.Controls/Primitives/TemplatedControl.cs b/src/Avalonia.Controls/Primitives/TemplatedControl.cs index 6e4ae748d9..db029d38c0 100644 --- a/src/Avalonia.Controls/Primitives/TemplatedControl.cs +++ b/src/Avalonia.Controls/Primitives/TemplatedControl.cs @@ -97,7 +97,7 @@ namespace Avalonia.Controls.Primitives /// public static readonly RoutedEvent TemplateAppliedEvent = RoutedEvent.Register( - "TemplateApplied", + nameof(TemplateApplied), RoutingStrategies.Direct); private IControlTemplate? _appliedTemplate; diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 45e66828c1..67c83ba13e 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -154,15 +154,15 @@ namespace Avalonia.Controls public static readonly RoutedEvent CopyingToClipboardEvent = RoutedEvent.Register( - "CopyingToClipboard", RoutingStrategies.Bubble); + nameof(CopyingToClipboard), RoutingStrategies.Bubble); public static readonly RoutedEvent CuttingToClipboardEvent = RoutedEvent.Register( - "CuttingToClipboard", RoutingStrategies.Bubble); + nameof(CuttingToClipboard), RoutingStrategies.Bubble); public static readonly RoutedEvent PastingFromClipboardEvent = RoutedEvent.Register( - "PastingFromClipboard", RoutingStrategies.Bubble); + nameof(PastingFromClipboard), RoutingStrategies.Bubble); readonly struct UndoRedoState : IEquatable { From a531335da4f4a194ac5cade92a880e46306b976d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Mon, 16 May 2022 21:39:47 +0200 Subject: [PATCH 06/12] Annotate handler parameter as can be null --- src/Avalonia.Base/Interactivity/Interactive.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Interactivity/Interactive.cs b/src/Avalonia.Base/Interactivity/Interactive.cs index 75f74ed3b3..a633b906e1 100644 --- a/src/Avalonia.Base/Interactivity/Interactive.cs +++ b/src/Avalonia.Base/Interactivity/Interactive.cs @@ -28,7 +28,7 @@ namespace Avalonia.Interactivity /// Whether handled events should also be listened for. public void AddHandler( RoutedEvent routedEvent, - Delegate handler, + Delegate? handler, RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, bool handledEventsToo = false) { @@ -77,7 +77,7 @@ namespace Avalonia.Interactivity /// /// The routed event. /// The handler. - public void RemoveHandler(RoutedEvent routedEvent, Delegate handler) + public void RemoveHandler(RoutedEvent routedEvent, Delegate? handler) { routedEvent = routedEvent ?? throw new ArgumentNullException(nameof(routedEvent)); handler = handler ?? throw new ArgumentNullException(nameof(handler)); From 3cb16c731cb9935a6f02fa28c7e41936da4914b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Tue, 17 May 2022 10:30:23 +0200 Subject: [PATCH 07/12] Revert --- src/Avalonia.Controls/Control.cs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Avalonia.Controls/Control.cs b/src/Avalonia.Controls/Control.cs index 7011acc3da..d6a5fa0727 100644 --- a/src/Avalonia.Controls/Control.cs +++ b/src/Avalonia.Controls/Control.cs @@ -53,7 +53,7 @@ namespace Avalonia.Controls /// Event raised when an element wishes to be scrolled into view. /// public static readonly RoutedEvent RequestBringIntoViewEvent = - RoutedEvent.Register(nameof(RequestBringIntoView), RoutingStrategies.Bubble); + RoutedEvent.Register("RequestBringIntoView", RoutingStrategies.Bubble); /// /// Provides event data for the event. @@ -126,15 +126,6 @@ namespace Avalonia.Controls set => SetValue(FlowDirectionProperty, value); } - /// - /// Occurs when an element wishes to be scrolled into view. - /// - public event EventHandler? RequestBringIntoView - { - add => AddHandler(RequestBringIntoViewEvent, value); - remove => RemoveHandler(RequestBringIntoViewEvent, value); - } - /// /// Occurs when the user has completed a context input gesture, such as a right-click. /// From a901ab38acad628b6abd3c9b58e5dcf046ed1cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Tue, 17 May 2022 10:31:42 +0200 Subject: [PATCH 08/12] Revert --- .../Primitives/SelectingItemsControl.cs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index e6d48ca149..a5726608a6 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -103,7 +103,7 @@ namespace Avalonia.Controls.Primitives /// public static readonly RoutedEvent IsSelectedChangedEvent = RoutedEvent.Register( - nameof(IsSelectedChanged), + nameof("IsSelectedChanged"), RoutingStrategies.Bubble); /// @@ -139,17 +139,6 @@ namespace Avalonia.Controls.Primitives IsSelectedChangedEvent.AddClassHandler((x, e) => x.ContainerSelectionChanged(e)); } - /// - /// Event that should be raised by items that implement to - /// notify the parent that their selection state - /// has changed. - /// - public event EventHandler? IsSelectedChanged - { - add { AddHandler(IsSelectedChangedEvent, value); } - remove { RemoveHandler(IsSelectedChangedEvent, value); } - } - /// /// Occurs when the control's selection changes. /// From dc84ea7edef1b76e9394c47943461bea33028e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Tue, 17 May 2022 10:32:43 +0200 Subject: [PATCH 09/12] Revert --- src/Avalonia.Controls/Window.cs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index 3a8a721eec..51ca91f5bf 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -172,13 +172,13 @@ namespace Avalonia.Controls /// Routed event that can be used for global tracking of window destruction /// public static readonly RoutedEvent WindowClosedEvent = - RoutedEvent.Register(nameof(WindowClosed), RoutingStrategies.Direct); + RoutedEvent.Register("WindowClosed", RoutingStrategies.Direct); /// /// Routed event that can be used for global tracking of opening windows /// public static readonly RoutedEvent WindowOpenedEvent = - RoutedEvent.Register(nameof(WindowOpened), RoutingStrategies.Direct); + RoutedEvent.Register("WindowOpened", RoutingStrategies.Direct); private readonly NameScope _nameScope = new NameScope(); @@ -445,24 +445,6 @@ namespace Avalonia.Controls } } - /// - /// Routed event that can be used for global tracking of window destruction. - /// - public event EventHandler? WindowClosed - { - add => AddHandler(WindowClosedEvent, value); - remove => RemoveHandler(WindowClosedEvent, value); - } - - /// - /// Routed event that can be used for global tracking of opening windows. - /// - public event EventHandler? WindowOpened - { - add => AddHandler(WindowOpenedEvent, value); - remove => RemoveHandler(WindowOpenedEvent, value); - } - /// /// Starts moving a window with left button being held. Should be called from left mouse button press event handler /// From 8e8f3ec15f433e75acdc65298ade2c5cf357acf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Tue, 17 May 2022 10:33:35 +0200 Subject: [PATCH 10/12] Revert --- src/Avalonia.Controls/Window.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index 51ca91f5bf..33057864a8 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -181,6 +181,7 @@ namespace Avalonia.Controls RoutedEvent.Register("WindowOpened", RoutingStrategies.Direct); + private readonly NameScope _nameScope = new NameScope(); private object? _dialogResult; private readonly Size _maxPlatformClientSize; From 0b99106f85a3f385e3b6b702dc3573ee4297d351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Tue, 17 May 2022 10:34:47 +0200 Subject: [PATCH 11/12] Revert --- src/Avalonia.Base/Interactivity/Interactive.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/Interactivity/Interactive.cs b/src/Avalonia.Base/Interactivity/Interactive.cs index a633b906e1..75f74ed3b3 100644 --- a/src/Avalonia.Base/Interactivity/Interactive.cs +++ b/src/Avalonia.Base/Interactivity/Interactive.cs @@ -28,7 +28,7 @@ namespace Avalonia.Interactivity /// Whether handled events should also be listened for. public void AddHandler( RoutedEvent routedEvent, - Delegate? handler, + Delegate handler, RoutingStrategies routes = RoutingStrategies.Direct | RoutingStrategies.Bubble, bool handledEventsToo = false) { @@ -77,7 +77,7 @@ namespace Avalonia.Interactivity /// /// The routed event. /// The handler. - public void RemoveHandler(RoutedEvent routedEvent, Delegate? handler) + public void RemoveHandler(RoutedEvent routedEvent, Delegate handler) { routedEvent = routedEvent ?? throw new ArgumentNullException(nameof(routedEvent)); handler = handler ?? throw new ArgumentNullException(nameof(handler)); From 0a7955420f1ac7ba356516fb1f9ef26c1ede0902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Tue, 17 May 2022 10:35:47 +0200 Subject: [PATCH 12/12] Fix --- src/Avalonia.Controls/Primitives/SelectingItemsControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index a5726608a6..ea20247b4b 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -103,7 +103,7 @@ namespace Avalonia.Controls.Primitives /// public static readonly RoutedEvent IsSelectedChangedEvent = RoutedEvent.Register( - nameof("IsSelectedChanged"), + "IsSelectedChanged", RoutingStrategies.Bubble); ///