I am trying re-parent controls from one panel to another like this:
oldPanel.Children.Remove(control);
newPanel.Children.Add(control);
Which works fine with every control until i try to do it with the LAST child of the oldPanel, where i get:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Avalonia.Visuals
StackTrace:
at Avalonia.Rendering.DeferredRenderer.Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds)
The panels in question are 4 different StackPanels in a DockPanel and it only happens when moving controls between certain StackPanels. If i only remove elements and don't add them to a new panel, the exception is never raised, this makes me think maybe i have to do something to fix the scenegraph before the next render? is there something like UIElement.UpdateLayout in wpf?
Some things I tried: - setting oldPanel.IsVisible to false fixes this but i want these panels to still be visible because i have their minWidth set. - calling InvalidateVisual InvalidateMeasure and InvalidateArrange on all the panels(including the dockpanel) and the control being moved. - using ISetLogicalParent.SetParent.
Am I just doing this wrong? I couldn't find any examples online of re-parenting controls at all.
User contributions licensed under CC BY-SA 3.0