有什么方法可以在WPF中创建粘性页脚吗? [英] Is there any way to create a sticky footer in WPF?

查看:64
本文介绍了有什么方法可以在WPF中创建粘性页脚吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在WPF中添加一个页脚.

这是我在此主题上发现的唯一问题:

I would like to have a sticky footer in WPF.

This is the only question that I found on this topic: Is there any way to create a sticky footer in xaml?

But the answer creates a fixed footer, not a sticky footer:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <Label Grid.Row="0" Grid.Column="0" Content="Label at the top"/>

    <DataGrid Grid.Row="1"/>

    <Label Grid.Row="2" Grid.Column="0" Content="Label at the bottom"/>
</Grid>

The problem with this solution is that when I put a DataGrid in the middle (Row 1) it occupies all the remaining empty space that pushes the bottom Label away.

I would like the bottom Label to stick to the bottom of the DataGrid when the DataGrid doesn't occupy the whole height and stay on screen when DataGrid is taller than the screen.

Pseudo code:

if DataGrid needs scrollbar
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
else
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

Example with numbers:

DataGrid needs a scrollbar:
    screen height: 1000 px
    filled data grid height: 2500 px
    sticky footer height: 30 px
    sticky footer y from top: 970 px (screen height - sticky footer height)

DataGrid does not need a scrollbar:
    screen height: 1000 px
    empty data grid height: 100 px
    sticky footer height: 30 px
    sticky footer y from top: 100 px (same as data grid height)

This is just an example, my screen is resizable, so the solution can't depend on screen size.

解决方案

DockPanel with inner Grid produce desired layout:

<DockPanel LastChildFill="False">
    <Label Content="Label at the top" DockPanel.Dock="Top"/>

    <Grid DockPanel.Dock="Top">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <DataGrid Grid.Row="0" />

        <Label Grid.Row="1" Grid.Column="0" Content="Label at the bottom"/>
    </Grid>
</DockPanel>

这篇关于有什么方法可以在WPF中创建粘性页脚吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆