2015-02-12 27 views
0

我正在使用Windows Phone 8應用程序,其中我有一個Stackpanel,並且我想在其中放置7個矩形。不管屏幕尺寸如何,我都希望這些矩形具有相同的高度。我嘗試設置Height="*",但它給錯誤。如何在7個相等高度的矩形中劃分堆棧面板

 <StackPanel> 
      <Rectangle Fill="Violet" Height="*"></Rectangle> 
      <Rectangle Fill="Indigo" Height="*"></Rectangle> 
      <Rectangle Fill="Blue" Height="*"></Rectangle> 
      <Rectangle Fill="Green" Height="*"></Rectangle> 
      <Rectangle Fill="Yellow" Height="*"></Rectangle> 
      <Rectangle Fill="Orange" Height="*"></Rectangle> 
      <Rectangle Fill="Red" Height="*"></Rectangle> 
     </StackPanel> 

任何人都可以幫助我嗎?

+1

不要使用'StackPanel'。這不是'StackPanel'的用途。使用'Grid'。 – Peter 2015-02-12 08:58:02

回答

2

下面應該爲你做:

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"> 
     <RowDefinition Height="*"> 
     <RowDefinition Height="*"> 
     <RowDefinition Height="*"> 
     <RowDefinition Height="*"> 
     <RowDefinition Height="*"> 
     <RowDefinition Height="*"> 
    <Grid.RowDefinitions> 

    <Rectangle Fill="Violet" Grid.Row="0" /> 
    <Rectangle Fill="Indigo" Grid.Row="1" /> 
    <Rectangle Fill="Blue" Grid.Row="2" /> 
    <Rectangle Fill="Green" Grid.Row="3" /> 
    <Rectangle Fill="Yellow" Grid.Row="4" /> 
    <Rectangle Fill="Orange" Grid.Row="5" /> 
    <Rectangle Fill="Red" Grid.Row="6" /> 
</Grid>