2011-03-31 41 views
5

我已经加入的StackPanel两个按钮和设置对准,如图中的代码如何对齐windows phone 7中的堆叠面板上的按钮?

<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
<Button Content="Button" Height="64" Name="button1" Width="160" HorizontalAlignment="Left" VerticalAlignment="Top"/> 
<Button Content="Button" Height="64" Name="button2" Width="160" HorizontalAlignment="Right" VerticalAlignment="Top"/> 
</StackPanel> 

但这并不与我的需求相匹配。我希望它像下图所示。

enter image description here

所以,我怎么能做到这一点?

+5

是Windows Phone 7吗?看起来像iphone :-) – Shoban 2011-03-31 07:18:02

+0

它的iPhone只。这是要求 – rubyraj 2011-03-31 07:24:48

+0

缩进标记和4个空格的代码,以便它在您的问题中正确显示。考虑在编辑问题时阅读右侧显示的Markdown文档。 – AnthonyWJones 2011-03-31 08:49:59

回答

6

事情是这样的:

<Grid 
    Width="480"> 

    <Grid.ColumnDefinitions> 
     <ColumnDefinition 
      Width="*" /> 
     <ColumnDefinition 
      Width="*" /> 
    </Grid.ColumnDefinitions> 

    <Button 
     Width="200" 
     Content="Clear" /> 

    <Button 
     Grid.Column="1" 
     Width="200" 
     Content="Options" 
     HorizontalAlignment="Right" 
     /> 

</Grid> 

更新:由于大众需求,这里是不固定的宽度或列的网格。

<Grid> 

    <Button 
     Width="150" 
     Content="Clear" 
     HorizontalAlignment="Left" 
     /> 

    <Button 
     Width="150" 
     Content="Options" 
     HorizontalAlignment="Right" 
     /> 

</Grid> 
+0

这两列真的有必要吗? – AnthonyWJones 2011-03-31 08:48:30

+0

与此我得到所需的出,但我gui感到不安是否有任何其他方式来做到这一点。我可以做到这一点,而不玩网格。 – rubyraj 2011-03-31 10:23:52

+0

@rubyraj:“干扰”是什么意思?除非你有其他的要求没有告诉我们,否则'Grid'是这个工作的正确工具? – AnthonyWJones 2011-03-31 12:42:55