对齐堆栈中的面板项目? [英] Align items in a stack panel?

查看:153
本文介绍了对齐堆栈中的面板项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想,如果我能有2控制在一个水平为导向的StackPanel,使正确的项目应停靠在右侧的StackPanel的。

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 following but it didn't work:

<StackPanel Orientation="Horizontal">
    <TextBlock>Left</TextBlock>
    <Button Width="30" HorizontalAlignment="Right">Right<Button>
</StackPanel>

在上面我希望按钮停靠在右侧的StackPanel。

In the snippet above I want the Button to be docked to the right side of the StackPanel.

注:我需要用的StackPanel,没有电网等进行

Note: I need it to be done with StackPanel, not Grid etc.

推荐答案

您可以实现这一 DockPanel中

<DockPanel Width="300">
    <TextBlock>Left</TextBlock>
    <Button HorizontalAlignment="Right">Right</Button>
</DockPanel>

不同的是,一个<一href="http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel.aspx"><$c$c>StackPanel将安排子元素成单行(垂直或水平),而一个<一个href="http://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel.aspx"><$c$c>DockPanel定义一个区域,您可以水平或垂直排列的子元素,相对于彼此(即码头属性更改元素相对于一对中的其他元素的位置,同一容器中。对齐属性,如的Horizo​​ntalAlignment ,改变相对于它的父元素的元素的位置)。

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).

这篇关于对齐堆栈中的面板项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆