WPF网格不会拉伸它的高度

时间:2013-02-04 10:32:52

标签: wpf

我想拉伸此窗口的Groupbox(高度)。我无法让它发挥作用。我究竟做错了什么? 我想要的是groupbox延伸到窗口的高度,但第一列不伸展。                                                                                                  

    <!-- PLAYER A -->
    <Border Grid.Row="0" Grid.Column="0" x:Name="PlayerA" Height="145" VerticalAlignment="Center">
        <Grid Height="145" VerticalAlignment="Top">
            <GroupBox x:Name="grpPlayerA" Header="Player A" Margin="10,14,0,0" RenderTransformOrigin="0.035,-0.717" Height="127" VerticalAlignment="Top">
                <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                    <Label x:Name="lblArtistA" Content="VENGABOYS" HorizontalAlignment="Left" Margin="3,3,0,0" VerticalAlignment="Top"/>
                    <Label x:Name="lblTitleA" Content="TO BRAZIL" HorizontalAlignment="Left" Margin="3,27,0,0" VerticalAlignment="Top"/>
                    <ProgressBar x:Name="prgPlayerA" HorizontalAlignment="Left" Height="15" Margin="5,53,0,0" VerticalAlignment="Top" Width="212"/>
                    <Image x:Name="imgPlayerA" HorizontalAlignment="Left" Height="62" Margin="220,6,0,0" VerticalAlignment="Top" Width="81"/>
                    <Button x:Name="btnPlayerAPlay" Content="Play" HorizontalAlignment="Left" Margin="5,79,0,0" VerticalAlignment="Top" Width="75"/>
                    <Button x:Name="btnPlayerAPauze" Content="Pauze" HorizontalAlignment="Left" Margin="92,79,0,0" VerticalAlignment="Top" Width="74"/>
                    <Button x:Name="btnPlayerAStop" Content="Stop" HorizontalAlignment="Left" Margin="178,79,0,0" VerticalAlignment="Top" Width="76"/>

                </Grid>
            </GroupBox>

        </Grid>
    </Border>

    <!-- PLAYER B-->
    <Border Grid.Row="0" Grid.Column="1" x:Name="PlayerB">
        <GroupBox x:Name="grpPlayerB" Header="Player B" Margin="0,14,16,0" Height="127" VerticalAlignment="Top">
            <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                <Label x:Name="lblArtistB" Content="VENGABOYS" HorizontalAlignment="Left" Margin="3,3,0,0" VerticalAlignment="Top"/>
                <Label x:Name="lblTitleB" Content="TO BRAZIL" HorizontalAlignment="Left" Margin="3,27,0,0" VerticalAlignment="Top"/>
                <ProgressBar x:Name="prgPlayerB" HorizontalAlignment="Left" Height="15" Margin="5,53,0,0" VerticalAlignment="Top" Width="212"/>
                <Image x:Name="imgPlayerB" HorizontalAlignment="Left" Height="62" Margin="220,6,0,0" VerticalAlignment="Top" Width="81"/>
                <Button x:Name="btnPlayerBPlay" Content="Play" HorizontalAlignment="Left" Margin="5,79,0,0" VerticalAlignment="Top" Width="75"/>
                <Button x:Name="btnPlayerBPauze" Content="Pauze" HorizontalAlignment="Left" Margin="92,79,0,0" VerticalAlignment="Top" Width="74"/>
                <Button x:Name="btnPlayerBStop" Content="Stop" HorizontalAlignment="Left" Margin="178,79,0,0" VerticalAlignment="Top" Width="76"/>

            </Grid>
        </GroupBox>
    </Border>

    <!-- HITLIJST -->
    <Border Grid.Row="1" Grid.Column="0" x:Name="Hitlijst" VerticalAlignment="Top" Margin="0,0,0,28">
        <Grid VerticalAlignment="Top">
            <Grid.RowDefinitions>
                <RowDefinition Height="0*"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <GroupBox x:Name="grpPlaylist" Header="Hitlijst" Margin="10,0" Grid.RowSpan="2" Height="275">
                <Grid VerticalAlignment="Top">
                    <ListBox x:Name="lbxHitlijst" Height="242" Margin="10,10,10,0" VerticalAlignment="Top">
                        <ListBoxItem Background="#FFF55F19" Content="1. Vengaboys - To Brazil (3:19)"/>
                        <ListBoxItem Background="#FFF91A1A" Content="2. Total Touch - Doo Be La Dee (3:60)"/>
                        <ListBoxItem Content="3. ATB - 9 PM Till I Come (3:33)"/>
                    </ListBox>

                </Grid>
            </GroupBox>

        </Grid>
    </Border>

    <Border Grid.Row="1" Grid.Column="1" x:Name="Info">
        <Grid>
            <GroupBox x:Name="grpInfo" Header="Info" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Height="282" Width="324">
                <Grid>
                    <TextBlock x:Name="txtLyrics" HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Lyrics" VerticalAlignment="Top" Height="119" Width="292"/>
                    <GroupBox x:Name="grpInfoInfo" Header="Gegevens" HorizontalAlignment="Left" Margin="10,134,0,0" VerticalAlignment="Top" Height="116" Width="292">
                        <Grid>
                            <Label x:Name="lblAlbum" Content="ALBUM: Hitzone 1" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.149,0.231"/>
                            <Label x:Name="lblYear" Content="JAAR: 1992" HorizontalAlignment="Left" Margin="10,36,0,0" VerticalAlignment="Top" RenderTransformOrigin="0,0.269"/>
                            <Label x:Name="lblArtists" Content="ARTIEST(EN): Vengaboys" HorizontalAlignment="Left" Margin="10,62,0,0" VerticalAlignment="Top"/>

                        </Grid>
                    </GroupBox>

                </Grid>
            </GroupBox>

        </Grid>
    </Border>
    <GroupBox x:Name="grpHitlijst" Header="Hitlijst --" Grid.ColumnSpan="2" Grid.RowSpan="2" Margin="0,0,10,10"/>
</Grid>

提前感谢它会很棒!

2 个答案:

答案 0 :(得分:1)

如果您希望GroupBox的高度延伸,为什么VerticalAlignment Top?将其切换为Stretch,它应该可以正常工作。

答案 1 :(得分:0)

请参阅本说明: WPF Groupbox height needs to change dynamically?

底线 - 将宽度和高度设置为“自动”(删除它们拥有的值), 如果你需要它也可以设置VerticalAlignment / Horizo​​ntal一个“Stretch”