Wpf 将网格行设置为“自动”,但不要扩展超过剩余可用空间

Wpf 将网格行设置为“自动”,但不要扩展超过剩余可用空间,wpf,Wpf,因为子控件是scrollviewer,所以我不能使用堆栈面板,因为它的增长趋势会超出父容器约束 我有一个有几行的网格,中间的一行需要折叠,当不包含太多内容时,但仍然扩展到*(剩余可用空间)。当满时,该行内部有一个滚动查看器,可以处理超过该点的溢出 <DataTemplate DataType="{x:Type IMPI:SettingGroup}"> <Grid> <Grid.RowDefinitions> &l

因为子控件是scrollviewer,所以我不能使用堆栈面板,因为它的增长趋势会超出父容器约束

我有一个有几行的网格,中间的一行需要折叠,当不包含太多内容时,但仍然扩展到
*
(剩余可用空间)。当满时,该行内部有一个滚动查看器,可以处理超过该点的溢出

<DataTemplate DataType="{x:Type IMPI:SettingGroup}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label Content="{Binding Name}" Grid.Row="0"/>
        <TextBlock Grid.Row="1" Text="{Binding Description}"/>

        <!-- I want this row to shrink when its size is less than the remaining space determined by "*" -->
        <TabControl Grid.Row="2" ItemsSource="{Binding Groups}" Visibility="{Binding Groups, Converter={StaticResource VisibleIfItemsPresent}}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" />
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <ScrollViewer>
                        <ContentPresenter Content="{Binding}"/>
                    </ScrollViewer>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>

        <ItemsControl Grid.Row="3" ItemsSource="{Binding Settings}" Visibility="{Binding Settings, Converter={StaticResource VisibleIfItemsPresent}}"/>

    </Grid>
</DataTemplate>


只需将
verticalignment=“top”
添加到选项卡控件中即可。它将根据ContentPresenter的内容垂直“折叠”,并增长到“*”行高设置的限制。一旦达到这一点,scrollviewer应该开始使用它的垂直滚动条。有没有办法计算第2行的MaxHeight?您需要具有最大高度的自动高度
只需将
verticalignment=“top”
添加到选项卡控件中即可。它将根据ContentPresenter的内容垂直“折叠”,并增长到“*”行高设置的限制。一旦达到这一点,scrollviewer应该开始使用它的垂直滚动条。有没有办法计算第2行的MaxHeight?您需要具有最大高度的自动高度<代码>