2confused4u
2confused4u

Reputation: 65

Change the order of controls in a panel?

Is there a simple way to change the order in which controls are displayed within a panel? I do not mean Z-Index. I mean explicitly setting the 'flow order'. Thank you.

Upvotes: 1

Views: 2714

Answers (1)

Emond
Emond

Reputation: 50692

The StackPanel and the Grid use a Children property of type UIElementCollection

By using Remove(At) and Insert you could change the order of the elements in the collection.

After that it depends on the Panel (Grid, Stack, Dock, ...) whether or not, and if how, it uses this order.

Some Panels, such as the Grid, also use attached properties (Grid.Column, Dock.Top) to position elements so there is no single way of re-ordering for all panels.

If the elements are added dynamically through data binding, re-ordering the data items in their collection might cause the Panel to display the controls in a different order.

Upvotes: 2

Related Questions