setting new parent
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.
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: setting new parent
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:
In your scenario, when you want to move the border from the Grid to the Canvas you will do the following:
Code: Select all
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
Code: Select all
_masterGrid->GetChildren()->Remove(border.GetPtr());
_rootCanvas->GetChildren()->Add(border.GetPtr());
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest