Align items in a stack panel?

前端 未结 9 1228
我寻月下人不归
我寻月下人不归 2020-12-04 10:23

I was wondering if I can have 2 controls in a horizontal-oriented StackPanel so that the right item should be docked to the right side of the StackPanel.

I tried the

9条回答
  •  一向
    一向 (楼主)
    2020-12-04 11:05

    You can achieve this with a DockPanel:

    
        Left
        
    
    

    The difference is that a StackPanel will arrange child elements into single line (either vertical or horizontally) whereas a DockPanel defines an area where you can arrange child elements either horizontally or vertically, relative to each other (the Dock property changes the position of an element relative to other elements within the same container. Alignment properties, such as HorizontalAlignment, change the position of an element relative to its parent element).

    Update

    As pointed out in the comments you can also use the FlowDirection property of a StackPanel. See @D_Bester's answer.

提交回复
热议问题