You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Avalonia控件适配窗口剩余可用高度问题求助

问题:让内容拉伸至窗口剩余可用高度

我正尝试让内容拉伸至窗口的剩余可用高度,当前布局代码如下:

<DockPanel>
    <!--MenuBar-->
    <Border DockPanel.Dock="Top">
        <Panel Margin="0,0,0,0" Height="60" Background="#005999">
            <DockPanel>
                <Label>Elements1</Label>
                <Label>Elements2</Label>
                <Panel Width="1" Background="#D3D3D3" Height="25" Margin="5,0,5,0"></Panel>
                <Label>Elements3</Label>
                <Panel Width="1" Background="#D3D3D3" Height="25" Margin="5,0,5,0"></Panel>
                <Label VerticalAlignment="Center" Foreground="Black" FontSize="18">Technology:</Label>
                <ComboBox SelectedIndex="0" Width="150" Height="28" FontSize="18" VerticalAlignment="Center"
                            Margin="7,0,5,0" CornerRadius="3" BorderBrush="#ADB2B6" Padding="10,2,0,2">
                    <ComboBox.Styles>
                        <Style Selector="ComboBoxItem">
                            <Setter Property="BorderBrush" Value="#D8DBDF" />
                            <Setter Property="BorderThickness" Value="1" />
                        </Style>
                    </ComboBox.Styles>
                    <ComboBoxItem>foo</ComboBoxItem>
                    <ComboBoxItem>bar</ComboBoxItem>
                </ComboBox>
            </DockPanel>
        </Panel>
    </Border>
    
    <ScrollViewer VerticalScrollBarVisibility="Visible">
        <StackPanel DockPanel.Dock="Top"
                    Height = "{Binding ActualHeight, ElementName=Mainwindow, Mode=OneWay}"
                    Orientation="Vertical"
                    HorizontalAlignment="Stretch"
                    ScrollViewer.VerticalScrollBarVisibility="Auto">
            <!--Content-->
            <Grid DockPanel.Dock="Bottom"
                        Margin="0,25,25,25"
                        Background="Gray">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                
                <Panel Grid.Column="0" Grid.Row="0"
                        HorizontalAlignment="Left"
                        Background="Green">
                    <StackPanel Orientation="Vertical">
                        <Label>TreeDataGrid</Label>
                        <Label>TreeDataGrid</Label>
                        <Label>TreeDataGrid</Label>
                        <Label>TreeDataGrid</Label>
                    </StackPanel>
                </Panel>
                
                <Panel Grid.Column="1" Grid.Row="0"
                        Margin="0,0,10,0" HorizontalAlignment="Left" >
                    <Panel Name="DashboardPanel"
                            Background="Beige"
                            HorizontalAlignment="Stretch"
                            Margin="0,0,25,0">
                        <Rectangle Fill="Blue" Width="200" Height="200"/>
                    </Panel>
                </Panel>
            </Grid>
        </StackPanel>
    </ScrollViewer>
</DockPanel>

我已尝试以下方法但未成功:

  • ClipToBounds="True"
  • VerticalAlignment="Stretch"
  • 将包含Grid的StackPanel设置为:Height = "{Binding ActualHeight, ElementName=Mainwindow, Mode=OneWay}"
  • 除当前代码中的Grid外,还使用过DockPanel和StackPanel,但均未实现动态高度渲染

内容的提问来源于stack exchange,提问作者Philipp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 13:36:03