1
我想知道是否可以将ScrollViewer控件中的水平滚动条停靠在顶部,而不是将其放在底部?如果没有,是否可以在ScrollViewer上方使用一个单独的滚动条控件,并以某种方式将ScrollBar_Scroll事件分配给它?WPF ScrollViewer - 将水平滚动条对齐到顶部?
在此先感谢!
我想知道是否可以将ScrollViewer控件中的水平滚动条停靠在顶部,而不是将其放在底部?如果没有,是否可以在ScrollViewer上方使用一个单独的滚动条控件,并以某种方式将ScrollBar_Scroll事件分配给它?WPF ScrollViewer - 将水平滚动条对齐到顶部?
在此先感谢!
当然 - 这里是修改移调网格行0和电网1行,这使水平滚动条上方为ScrollViewer
的默认模板:
<ControlTemplate x:Key="ScrollViewerHorizontalOnTopTemplate" TargetType="{x:Type ScrollViewer}">
<Grid x:Name="Grid" Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="17"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle x:Name="Corner"
Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
Grid.Column="1" Grid.Row="0"/>
<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Grid.Column="0" Grid.Row="1" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False"/>
<ScrollBar x:Name="PART_VerticalScrollBar"
Cursor="Arrow"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
Grid.Column="1" Grid.Row="1"
AutomationProperties.AutomationId="VerticalScrollBar"
Maximum="{TemplateBinding ScrollableHeight}"
Minimum="0"
Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
ViewportSize="{TemplateBinding ViewportHeight}"/>
<ScrollBar x:Name="PART_HorizontalScrollBar"
Cursor="Arrow"
Grid.Column="0"
AutomationProperties.AutomationId="HorizontalScrollBar"
Maximum="{TemplateBinding ScrollableWidth}"
Minimum="0"
Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
Orientation="Horizontal"
ViewportSize="{TemplateBinding ViewportWidth}"/>
</Grid>
</ControlTemplate>
套用这个范本,您ScrollViewer
和你应该全部设置。
Expression Blend使这样的任务变得微不足道 - 我推荐它。
它的工作原理!这真的有帮助!然而,你的XAML中的“x:key”给了我一个错误,所以我只是将它删除了,它就起作用了!非常感谢你,杰伊! 编辑:这是你的+1! – 2010-08-24 17:01:04
@ xplinux557如果将模板存储为资源并且不希望将其应用于资源范围内的所有ScrollViewer对象,则使用'x:Key'。 – Jay 2010-08-24 17:06:11