滚动条在WPF中的默认位置问题 [英] Scroll bar default position issue in WPF

查看:162
本文介绍了滚动条在WPF中的默认位置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个WPF屏幕,默认情况下,滚动条显示在屏幕的右下方。我默认需要它在屏幕的左侧和顶部。我使用滚动条视图,水平/垂直滚动条可见性=自动。

请帮我在显示的起始位置显示滚动条屏幕,以便用户无需滚动它以查看屏幕的起点。

提前致谢。



什么我试过了:



< ScrollViewer Horizo​​ntalScrollBarVisibility =AutoVerticalScrollBarVisibility =Auto>

Hi,

I have a WPF screen in which the scroll bars are displayed in the right and down sides of the screen by default. I need it on the left and top sides of the screen by default.I am using a scrollbarviewer with horizontal/vertical scrollbarvisibility=Auto.
Please help me to display the scroll bars in the starting position of the screen so that user no need to scroll it to see the starting point of the screen.
Thanks in advance.

What I have tried:

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">

推荐答案

您可以使用ControlTemplate移动滚动条的位置。

MSDN有一个示例来设置左侧的垂直条:ScrollViewer ControlTemplate示例 [ ^ ]



放水平顶部的栏,改变它的Grid.Ro w为0并调整行定义,以便第一行为auto。 ScrollContentPresenter进入第1行。



You can move the location of the scrollbar using a ControlTemplate.
MSDN has an example to set the vertical bar on the left: ScrollViewer ControlTemplate Example[^]

To put the horizontal bar on the top, change its Grid.Row to 0 and adjust the row definitions so that the first row is auto. The ScrollContentPresenter goes in row 1.

<Style x:Key="LeftScrollViewer" TargetType="{x:Type ScrollViewer}">
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ScrollViewer}">
        <Grid>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
          </Grid.RowDefinitions>

          <ScrollContentPresenter Grid.Column="1" Grid.Row="1"/>

          <ScrollBar Name="PART_VerticalScrollBar"
            Value="{TemplateBinding VerticalOffset}"
            Maximum="{TemplateBinding ScrollableHeight}"
            ViewportSize="{TemplateBinding ViewportHeight}"
            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
          <ScrollBar Name="PART_HorizontalScrollBar"
            Orientation="Horizontal"
            Grid.Column="1"
            Value="{TemplateBinding HorizontalOffset}"
            Maximum="{TemplateBinding ScrollableWidth}"
            ViewportSize="{TemplateBinding ViewportWidth}"
            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
          
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>


这篇关于滚动条在WPF中的默认位置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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