From 6b13c81527796fd1be7792badd0ce1faadf6e222 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 22 Apr 2023 00:42:43 +0200 Subject: [PATCH 1/3] Raise WindowBase.Resized before SizeChanged. --- src/Avalonia.Controls/WindowBase.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index c2523207e4..463eda4f3c 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/src/Avalonia.Controls/WindowBase.cs @@ -232,14 +232,16 @@ namespace Avalonia.Controls { FrameSize = PlatformImpl?.FrameSize; - if (ClientSize != clientSize) + var clientSizeChanged = ClientSize != clientSize; + + ClientSize = clientSize; + OnResized(new WindowResizedEventArgs(clientSize, reason)); + + if (clientSizeChanged) { - ClientSize = clientSize; LayoutManager.ExecuteLayoutPass(); Renderer.Resized(clientSize); } - - OnResized(new WindowResizedEventArgs(clientSize, reason)); } /// From 9f3dbfff6a3e66ac4284edf0332b8168df1d7b7e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 25 Apr 2023 22:31:44 +0200 Subject: [PATCH 2/3] Added docs to clarify difference with SizeChanged. --- src/Avalonia.Controls/WindowBase.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index 463eda4f3c..0017630a75 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/src/Avalonia.Controls/WindowBase.cs @@ -83,6 +83,19 @@ namespace Avalonia.Controls /// /// Occurs when the window is resized. /// + /// + /// Although this event is similar to the event, they are + /// conceptually different: + /// + /// - is a window-level event, fired when a resize notification arrives + /// from the platform windowing subsystem. The event args contain details of the source of + /// the resize event in the property. This + /// event is raised before layout has been run on the window's content. + /// - is a layout-level event, fired when a layout pass + /// completes on a control. is present on all controls + /// and is fired when the control's size changes for any reason, including a + /// event in the case of a Window. + /// public event EventHandler? Resized; public new IWindowBaseImpl? PlatformImpl => (IWindowBaseImpl?) base.PlatformImpl; From 6c8afc714c2fa1a4797ab2d2a914c1645f086c00 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 25 Apr 2023 22:54:52 +0200 Subject: [PATCH 3/3] Correctly handle TreeViewPage data context change. Fixes #11120. --- .../Diagnostics/Views/TreePageView.xaml.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs index 66be6b5041..b0aea64994 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs @@ -39,16 +39,6 @@ namespace Avalonia.Diagnostics.Views AdornerLayer.SetIsClipEnabled(_adorner, false); } - protected override void OnDataContextChanged(EventArgs e) - { - base.OnDataContextChanged(e); - - ((TreePageViewModel)DataContext!).ClipboardCopyRequested += (sender, s) => - { - TopLevel.GetTopLevel(this)?.Clipboard?.SetTextAsync(s); - }; - } - protected void AddAdorner(object? sender, PointerEventArgs e) { var node = (TreeNode?)((Control)sender!).DataContext; @@ -108,9 +98,27 @@ namespace Avalonia.Diagnostics.Views _currentLayer = null; } + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == DataContextProperty) + { + if (change.GetOldValue() is TreePageViewModel oldViewModel) + oldViewModel.ClipboardCopyRequested -= OnClipboardCopyRequested; + if (change.GetNewValue() is TreePageViewModel newViewModel) + newViewModel.ClipboardCopyRequested += OnClipboardCopyRequested; + } + } + private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } + + private void OnClipboardCopyRequested(object? sender, string e) + { + TopLevel.GetTopLevel(this)?.Clipboard?.SetTextAsync(e); + } } }