简体   繁体   中英

StackPanel in Grid: limit height

I have a big main grid with several rows and columns. I want to place in one of these cells a vertical stackpanel. In this stackpanel there is a textblock and a scrollviewer. My problem is, that the stackpanel doesn't get limited by the cell, instead the stackpanel gets big enough to fit the whole scrollviewer.

How can I solve this?

EDIT: my xaml code:

<Grid x:Name="Grid1" Margin="120,0,0,0" Width="1244">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0*"/>
                        <ColumnDefinition Width="33*"/>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition Width="50*"/>
                        <ColumnDefinition Width="40"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="71"/>
                        <RowDefinition Height="40"/>
                        <RowDefinition/>
                        <RowDefinition Height="20"/>
                    </Grid.RowDefinitions>
                    <StackPanel Grid.Column="3" Grid.Row="2" Grid.ColumnSpan="2" Margin="0">
                        <TextBlock TextWrapping="Wrap" FontSize="48" Margin="0" VerticalAlignment="Top" Foreground="#FF0083FF" Text="Top 10:" HorizontalAlignment="Left" FontFamily="Segoe UI Light"/>
                        <ScrollViewer Margin="0,20,0,0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible">
                            <StackPanel>
                                <ListView x:Name="TopListView" ItemsSource="{Binding}" SelectionMode="None" Foreground="White" >
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <StackPanel >
                                                    <TextBlock FontSize="32" Text="1" Foreground="#FF0083FF"/>
                                                </StackPanel>
                                                <TextBlock Text="{Binding Text}" Foreground="Black" 
                                                    FontSize="16" Margin="0,0,0,0" TextWrapping="Wrap" />

                                            </StackPanel>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                            </StackPanel>
                        </ScrollViewer>
                    </StackPanel>

                </Grid>

Use another Grid instead of a StackPanel:

<Grid Grid.Column="3" Grid.Row="2" Grid.ColumnSpan="2" Margin="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <TextBlock FontSize="48" FontFamily="Segoe UI Light"
               Foreground="#FF0083FF" HorizontalAlignment="Left"
               TextWrapping="Wrap" Text="Top 10:"/>
    <ScrollViewer Grid.Row="1" Margin="0,20,0,0"
                  HorizontalScrollBarVisibility="Disabled"
                  VerticalScrollBarVisibility="Visible">
        ...
    </ScrollViewer>
</Grid >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM