本文介绍了在我的应用程序中全局更改滚动条的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在触摸屏计算机上运行的 WPF 应用程序.我想将应用程序中的所有滚动条更改为更宽.有没有办法在全球范围内做到这一点?

I have a WPF application that runs on a touch screen computer. I'd like to change all of the scroll bars in the app to be much wider. Is there a way to do that globally?

推荐答案

你必须覆盖scrollViewer的默认模板来增加垂直滚动条的宽度.要在所有滚动条上应用模板,请将覆盖样式放在您的应用资源中 -

Yo have to override the default template of scrollViewer to increase the width of vertical scrollbar. To apply the template across all your scrollbars put the override style in your App resources -

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

          <ScrollContentPresenter Grid.Column="1"/>

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

        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

你可以将 'PART_VerticalScrollBar' 的宽度设置为你想要的宽度(比如上面例子中的 40).把这个样式放在 Application Resources (App.xaml) 下它适用于整个应用程序.

You can set width of 'PART_VerticalScrollBar' to your desired width (say 40 as in example above).Placing this style under Application Resources (App.xaml) makes it applied across complete application.

这篇关于在我的应用程序中全局更改滚动条的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 23:18