Rick
Topic Author
Posts: 50
Joined: 26 Nov 2013, 15:35

setting new parent

01 May 2015, 19:29

My border has a grid as it's parent. However, when I selected the item I want to change it's parent to a canvas but when I try to add the border to the canvas I get an error saying it already has a parent. How can I change parents? I assume I need to do this in order to have my border draw on the canvas vs the grid.
 
User avatar
sfernandez
Site Admin
Posts: 3222
Joined: 22 Dec 2011, 19:20

Re: setting new parent

06 May 2015, 01:53

As you noticed UI elements can only have a unique logical parent. But Parent is automatically updated when you add or remove an element to or from a container:
contentControl->SetContent(border.GetPtr()); // border Parent = contentControl
contentControl->SetContent(0); // border Parent = null
stackPanel->GetChildren()->Add(border.GetPtr()); // border Parent = stackPanel
stackPanel->GetChildren()->Remove(border.GetPtr()); // border Parent = null      
In your scenario, when you want to move the border from the Grid to the Canvas you will do the following:
_masterGrid->GetChildren()->Remove(border.GetPtr());
_rootCanvas->GetChildren()->Add(border.GetPtr()); 

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest