【问题标题】:Grid Layouts in silverlightSilverlight 中的网格布局
【发布时间】:2011-11-01 10:28:38
【问题描述】:

我有两个网格行,它们的内容会有所不同。

我希望顶行的内容在行内垂直居中。

并且底行与底部垂直对齐。

<Grid>     
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="60*" />
    </Grid.RowDefinitions>  
    <Grid Grid.Row="0" VerticalAlignment="Top">
        <Grid VerticalAlignment="Center">
            <StackPanel>
                ...
            </StackPanel>                
        </Grid>
    </Grid>

    <StackPanel Grid.Row="1" VerticalAlignment="Bottom" d:LayoutOverrides="GridBox">
         ...           
    </StackPanel>
</Grid>

这应该是它的样子。

  +-----------------------------+               +--------------------------------+
  |                             |               |                                |
  |                             |               |                                |
  |                             |               |                                |
  | Content Centered            |               |                                |
  |                             |               |                                |
  |                             |               | Content Centered               |
  |                             |               |                                |
  +-----------------------------+     or        |                                |
  |                             |               |                                |
  |                             |               |                                |
  |                             |               |                                |
  |                             |               +--------------------------------+
  |                             |               |                                |
  | Content at the bottom       |               | Content at the bottom          |
  +-----------------------------+               +--------------------------------+

行的内容可能会有所不同,我曾在某些时候使用过行定义,但它不起作用,因为我不知道任何一行的固定高度。

【问题讨论】:

  • 嗯,你需要定义一些RowDefinitions 否则你不会走远。另外,如果您需要布局方面的帮助,请绘制一张该死的图像。
  • 有关 RowDefinition 值,请参见 msdn.microsoft.com/en-us/library/…,但您可以将 Auto 和 * 作为值......它们不必固定

标签: silverlight windows-phone-7


【解决方案1】:

所以,正如我所说,Grid.Row="1" 没有效果,除非您使用定义一系列 RowDefinition 元素。反正你描述的问题很简单,

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid VerticalAlignment="Center">
            <!-- stuff here is center aligned -->
        </Grid>
    </Grid>
    <Grid Grid.Row="1">
        <Grid VerticalAlignment="Bottom">
            <!-- stuff here is bottom aligned -->
        </Grid>
    </Grid>
</Grid>

【讨论】:

  • VerticalContentAlignment 不存在。我正在为 windows-phone 7 开发
  • 我猜他的意思是VerticalAlignment
  • 不,我没有。 msdn.microsoft.com/en-us/library/…(Windows Phone 支持,但 Grid 元素不支持。)
  • 我添加了一个行定义,这样我就有了底行的最小高度,顶行将适合自动。
  • 我是否必须在命名空间中添加任何内容才能使VerticalContentAlignment 工作?
猜你喜欢
  • 2011-11-29
  • 1970-01-01
  • 2011-01-26
  • 2011-04-20
  • 2011-10-28
  • 2013-04-24
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
相关资源
最近更新 更多