Page 1 of 1

setting new parent

Posted: 01 May 2015, 19:29
by Rick
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.

Re: setting new parent

Posted: 06 May 2015, 01:53
by sfernandez
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());