From e17f18de45ed3b9c1c851dafefeb904f62346329 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 10 Nov 2020 17:10:38 +0100 Subject: [PATCH] Update SelectionBoxItem on visual tree attach. Fixes initial sizing of `SelectionBoxItem` when it's a control. --- src/Avalonia.Controls/ComboBox.cs | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs index 02a9daee75..7f2acb58fe 100644 --- a/src/Avalonia.Controls/ComboBox.cs +++ b/src/Avalonia.Controls/ComboBox.cs @@ -173,11 +173,10 @@ namespace Avalonia.Controls ComboBoxItem.ContentTemplateProperty); } - /// - protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) + protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { - base.OnAttachedToLogicalTree(e); - this.UpdateSelectionBoxItem(this.SelectedItem); + base.OnAttachedToVisualTree(e); + this.UpdateSelectionBoxItem(SelectedItem); } /// @@ -373,19 +372,22 @@ namespace Avalonia.Controls if (control != null) { - control.Measure(Size.Infinity); - - SelectionBoxItem = new Rectangle + if (VisualRoot is object) { - Width = control.DesiredSize.Width, - Height = control.DesiredSize.Height, - Fill = new VisualBrush + control.Measure(Size.Infinity); + + SelectionBoxItem = new Rectangle { - Visual = control, - Stretch = Stretch.None, - AlignmentX = AlignmentX.Left, - } - }; + Width = control.DesiredSize.Width, + Height = control.DesiredSize.Height, + Fill = new VisualBrush + { + Visual = control, + Stretch = Stretch.None, + AlignmentX = AlignmentX.Left, + } + }; + } } else {