有什么方法可以在 WPF 中创建粘性页脚吗?
Is there any way to create a sticky footer in WPF?
我想在 WPF 中有一个粘性页脚。
这是我在这个主题上发现的唯一问题:
Is there any way to create a sticky footer in xaml?
但是答案创建了一个 fixed 页脚,而不是 sticky 页脚:
<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>
这个解决方案的问题是,当我在中间(第 1 行)放置一个 DataGrid
时,它占据了所有剩余的空 space,将底部 Label
推开。
我希望底部 Label
在 DataGrid
未占据整个高度时粘在 DataGrid
的底部,并在 [=13= 时留在屏幕上] 比屏幕还高。
伪代码:
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)
这只是一个例子,我的屏幕是可调整大小的,所以解决方案不能依赖于屏幕大小。
带有内部网格的 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>
我想在 WPF 中有一个粘性页脚。
这是我在这个主题上发现的唯一问题: Is there any way to create a sticky footer in xaml?
但是答案创建了一个 fixed 页脚,而不是 sticky 页脚:
<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>
这个解决方案的问题是,当我在中间(第 1 行)放置一个 DataGrid
时,它占据了所有剩余的空 space,将底部 Label
推开。
我希望底部 Label
在 DataGrid
未占据整个高度时粘在 DataGrid
的底部,并在 [=13= 时留在屏幕上] 比屏幕还高。
伪代码:
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)
这只是一个例子,我的屏幕是可调整大小的,所以解决方案不能依赖于屏幕大小。
带有内部网格的 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>