2015-05-02 34 views
0

我已经设置了一个Windows Phone 8.1项目,现在我正试图在水平靠近布局底部的位置放置一个按钮。如何使用网格行和列定义来定位按钮?

到目前为止,我已经想通了以下居中布局上的按钮,但 Grid.Row设置似乎并没有对垂直定位产生任何影响,因为我的预期。

有谁知道我可以如何将按钮放置在屏幕的底部?目前它在屏幕中央,但在屏幕上方一半处需要朝向屏幕底部。

<Page x:Class="LC_Points.MainPage" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:local="using:LC_Points" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" 
     DataContext="{Binding Source={StaticResource Locator}, 
          Path=MainViewModel}" 
     mc:Ignorable="d"> 
    <Grid> 
     <Button Grid.Row="2" 
       Content="Calculate" 
       HorizontalAlignment="Center"/> 
    </Grid> 
</Page> 

回答

1

之前设置元素的Grid.Row属性,首先你要定义网格的行。

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition></RowDefinition> 
     <RowDefinition></RowDefinition> 
    </Grid.RowDefinitions> 
    <Button Grid.Row="1" Content="Click Me!" /> 
</Grid> 

如果更改高度RowDefinitions性能,可以轻松定位按钮垂直。

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="90*"></RowDefinition> 
     <RowDefinition Height="10*"></RowDefinition> 
    </Grid.RowDefinitions> 
    <Button Grid.Row="1" Content="Click Me!" /> 
</Grid> 

10 *表示10%的网格。星的总和必须等于100.

+0

谢谢,那么如何使用网格定义水平定位?此时按钮左对齐,需要水平居中。 –

+0

同样,你应该定义列。拆分网格三个相等的列(没有宽度属性),并将按钮的grid.column属性设置为1. –

+0

好吧,我试过了。 http://hastebin.com/uyidilimog.xml但按钮现在是右下角。你能展示一个代表你的意思的例子吗? –