Browse Source

Check visual parent is not already set.

When setting the visual parent of a control, make sure that it's not
already set. The code in issue #513 was trying to reparent an already
parented control, causing problems - this makes sure that this can't
happen.
Steven Kirk 9 years ago
parent
commit
ab60beaa54
1 changed files with 5 additions and 0 deletions
  1. 5 0
      src/Avalonia.SceneGraph/Visual.cs

+ 5 - 0
src/Avalonia.SceneGraph/Visual.cs

@@ -442,6 +442,11 @@ namespace Avalonia
         /// <param name="value">The visual parent.</param>
         private void SetVisualParent(Visual value)
         {
+            if (value != null && _visualParent != null)
+            {
+                throw new InvalidOperationException("The control already has a visual parent.");
+            }
+
             if (_visualParent == value)
             {
                 return;