wpf - 有没有办法在 WPF 中创建一个粘性页脚?
问题描述
我想在 WPF 中有一个粘性页脚。
这是我在这个主题上发现的唯一问题: 有没有办法在 xaml 中创建粘性页脚?
但是答案会创建一个固定的页脚,而不是一个粘性页脚:
<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>
该解决方案的问题在于,当我将 aDataGrid
放在中间(第 1 行)时,它会占据所有剩余的空白空间,从而将底部Label
推开。
当底部不占据整个高度时,我希望底部Label
粘在底部,并且在高于屏幕时留在屏幕上。DataGrid
DataGrid
DataGrid
伪代码:
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>
数字示例:
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)
这只是一个例子,我的屏幕是可调整大小的,所以解决方案不能依赖于屏幕大小。
解决方案
带有内部 Grid 的 DockPanel 产生所需的布局:
<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>
推荐阅读
- c++ - C++ (x == 1) 与 (x & 1) 相同
- laravel - 使用 Passport Password Grants 和/或 Guzzle 时服务器冻结
- python-3.x - 如何为 RNN/LSTM 模型重塑数据集?
- apache-spark - Spark structured streaming foreachpartition / connection pooling issue
- python - Pandas 数据框 DateOffset 的偏移年份
- javascript - PrimeNG SelectButton with TEMPLATE 无法正确显示
- fabricjs - FabricJS - 运行 toDataURL 时“可能无法导出受污染的画布”JS 错误
- c# - C# HttpWebResponse 上传 PDF 不起作用/适用于 word 文档
- php - 使用 php 在 HTML 表中显示 sql 数据
- javascript - 为多个表设置点击事件处理程序