我不确定这是否可以在wpf中使用,但是,假设我在页面的网格中有多个文本块和其他控件
<TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="1" FontSize="30"
Text="Station" HorizontalAlignment="Left" Margin="65.2,0,0,3"
VerticalAlignment="top" Width="104" Height="47" />
<ComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="1"
HorizontalAlignment="Left" Margin="50.2,2,0,0" VerticalAlignment="Bottom"
Width="120" Height="22" />
<TextBlock Grid.Row="2" Grid.Column="4" Text="Date" FontSize="30"
HorizontalAlignment="Left" Margin="59.8,0,0,5" VerticalAlignment="top"
Height="45" Width="72" />
<DatePicker Grid.Row="2" Grid.Column="4" HorizontalAlignment="Left"
Margin="59.8,0,0,0" VerticalAlignment="Bottom"
RenderTransformOrigin="1.078,0.417" Height="24" Width="102" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="Item" FontSize="30"
HorizontalAlignment="Left" Margin="59.8,0,0,5" VerticalAlignment="top"
Height="45" Width="72" />
<TextBlock Grid.Row="3" Grid.Column="1" Text="UoM" FontSize="30"
HorizontalAlignment="Left" Margin="59.8,0,0,5" VerticalAlignment="top"
Height="45" Width="72" />
...
是否有办法封装这些控件并将它们保留在屏幕顶部的边框中,即使代码下方的文本框向下滚动也是如此。即,当您向下滚动页面的其余部分时,类似于HTML标题的内容会停留在屏幕的顶部?
答案 0 :(得分:0)
我会在底部使用滚动查看器来控制你的控件,让网格处理静态定位。
像
这样的东西<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border>
<!-- Your static header here -->
</Border>
<ScrollViewer Grid.Row="1">
<StackPanel>
<!-- Your scrolling content here -->
</StackPanel>
</ScrollViewer>
</Grid>