2

我有一个大的主网格,有几行和几列。我想在其中一个单元格中放置一个垂直堆栈面板。在这个堆栈面板中有一个文本块和一个滚动查看器。我的问题是,stackpanel 不受单元格的限制,而是 stackpanel 变得足够大以适合整个滚动查看器。

我该如何解决这个问题?

编辑:我的 xaml 代码:

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

1 回答 1

4

使用另一个 Grid 而不是 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 >
于 2013-08-12T12:38:48.300 回答