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
{