设置相对于可用空间的元素高度

时间:2017-08-22 12:04:03

标签: wpf xaml

我的网格目前定义了以下行:

<RowDefinition Height="50" />
<RowDefinition Height="*" />

不幸的是,我加载到这里的数据,即使使用ScrollViewer,也会使窗口太“高”,而且我的屏幕底部会丢失一些。

为了解决这个问题,我正在考虑做Height="* - x"这样的事情,其中​​x是我想要从*中减去的任何值减去的像素数量。

不幸的是,这不是有效的标记,所以我该怎么做?

1 个答案:

答案 0 :(得分:0)

我不确定这是不是你要求的:

<DockPanel>
    <Button DockPanel.Dock="Bottom" Content="Button" />

    <ScrollViewer>
        <Grid DockPanel.Dock="Top" Height="2000">
            <Grid.RowDefinitions>
                <RowDefinition Height="50" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <TextBlock Text="Grid.Row=0" />

            <Rectangle Fill="Crimson"  Grid.Row="1" RadiusX="100" RadiusY="100" />
        </Grid>
    </ScrollViewer>
</DockPanel>

Scroll at top

Scroll at bottom