Removing an Element From a Border

Nathan Sokalski 4,126 Reputation points

I have an element inside a Border, and want to move that element to another location. However, I first need to remove it from the Border. Panel controls (such as Grid & StackPanel) have a Children property on which I would call the Remove method, but because Border is not a Panel, I cannot do this. What can I do to remove the element from the Border so that I can use it somewhere else (such as adding it to a Grid or StackPanel)? Thanks.

Universal Windows Platform (UWP)
{count} votes

2 answers

Sort by: Most helpful
  1. Richard Zhang-MSFT 6,936 Reputation points


    Welcome to Microsoft Q&A.

    Border has Child property, if you set it to null, you can also remove child element.

    var rect = TestRect;
    // remove child here
    TestBorder.Child = null;
    // add to another panel


    0 comments No comments

  2. Sabrina Cosolo 126 Reputation points

    Usually when I use a Border I put inside it a Grid or a StackPanel and this reduces your problem to make the same action you do with any other Grid or StackPanel.

    <Border >
    <Grid x:Name="Container">
    <!--Here you can add all children and then remove them-->



    0 comments No comments