Add child to specific location in tree
I can add a new element to a Canvas using canvas.Children.Add()
But how do I place that element above or below an existing element in the xaml tree?
Is this the way it is supposed to be done?
But how do I place that element above or below an existing element in the xaml tree?
Is this the way it is supposed to be done?
Code: Select all
int index = canvas.Children.IndexOf(existingElement);
canvas.Children.Insert(index + 1, newElement);
-
sfernandez
Site Admin
- Posts: 3005
- Joined:
Re: Add child to specific location in tree
Yes, you can use Insert to add a child in a specific order.
This will affect the logical order and also how children are rendered.
If you only care about render order you can then use Panel.ZIndex property (higher value indicates that is rendered later):
This will affect the logical order and also how children are rendered.
If you only care about render order you can then use Panel.ZIndex property (higher value indicates that is rendered later):
Code: Select all
Panel.SetZIndex(newElement, 10);
Panel.SetZIndex(existingElement, 20);
canvas.Children.Add(newElement);
Re: Add child to specific location in tree
Thanks for your feedback, marking this as solved.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests