WPF Scrollviewer 不让我滚动并认为它的高度是无限的

WPF Scrollviewer does not let me scroll and thinks its hight is infinite

我遇到了一个小问题,我无法解决。问题是当我初始化滚动条时,它不仅仅停留在屏幕上。更具体地说,我认为它的高度实际上设置为“自动”,因为它不允许我滚动并且它会无限大。另一方面,当我将高度设置为“500”时,它允许我滚动浏览它并且一切正常。

主要window:

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>

            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"></ColumnDefinition>

            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>

            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <!-- 
        <Frame x:Name="MainFrame" Grid.Row ="1" Grid.Column="1" Content="{Binding CurrPage}" Source="../pages/test_page.xaml" />
        
        -->
        <Grid Height="500">
            <local:MessageList>
                <local:ChatListControl VerticalAlignment="Top">

                </local:ChatListControl>
            </local:MessageList>
        </Grid>

    </Grid>

聊天列表控件(滚动条所在的地方):

<Grid DataContext="{x:Static local:ChatsDesignModule.Instance}" Background="White">

        <ScrollViewer VerticalScrollBarVisibility="Visible">
            <ItemsControl ItemsSource="{Binding Items}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <local:OneMessageTMP />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>

    </Grid>

有什么方法可以让我在第一个 window 中绑定当前大小,只需将它绑定到已经存在的东西上,或者我必须以某种方式获取当前最大值,然后使用它进行设置一 ? 提前致谢。如果您对代码有任何疑问,请告诉我,如果需要,我会解释/提供更多代码:)

Height="Auto" 设置为 Height="*"Height="Auto" 将尽可能多地提供网格行的内容 space。因此滚动查看器没有任何内容可以滚动。