对齐堆栈中的面板项目?堆栈、面板、项目

由网友(伪妆)分享简介:我在想,如果我能有2控制在一个水平为导向的StackPanel,使正确的项目应停靠在右侧的StackPanel的。I was wondering if I can have 2 controls in a horizontal-oriented StackPanel so that the right item sh...

我在想,如果我能有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>

不同的是,一个StackPanel将安排子元素成单行(垂直或水平),而一个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).

阅读全文

相关推荐

最新文章