如何将stackpanel分成7个等高的矩形

How to divide stackpanel in 7 equal height rectangles

我正在开发 Windows Phone 8 个应用程序,其中我有一个 Stackpanel,我想在其中放置 7 个矩形。无论屏幕尺寸如何,我都希望这些矩形具有相同的高度。我尝试设置 Height="*" 但出现错误。

        <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>

有人可以帮我吗?

以下应该为您完成:

<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>

还有一个 UniformGrid 可以为您做到这一点:

<UniformGrid Columns="1" Rows="7" />