如何在 WPF ScrollViewer 中增加滚动条宽度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1321247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:54:28  来源:igfitidea点击:

How to increase scrollbar width in WPF ScrollViewer?

wpfscrollbarwidthscrollviewer

提问by JohnIdol

I am working on a touch screen on a small device and the custom width of the scroll-bar is no good as one of my requirements is that everything needs to be doable by finger gestures.

我正在小型设备上的触摸屏上工作,滚动条的自定义宽度不好,因为我的要求之一是一切都需要通过手指手势来完成。

How can I set the width of the WPF ScrollViewer scrollbar?

如何设置 WPF ScrollViewer 滚动条的宽度?

Note that I don't wanna change the width of all the scrollbars on the device (doable through windows settings) - only the ones in my app.

请注意,我不想更改设备上所有滚动条的宽度(可通过 Windows 设置进行)-仅更改我应用中的滚动条。

回答by Kent Boogaart

The ScrollBartemplate reaches out for system parameters to determine its width/height (depending on orientation). Therefore, you can override those parameters:

ScrollBar模板伸出为系统参数,以确定其宽度/高度(取决于方向)。因此,您可以覆盖这些参数:

<ScrollViewer>
    <ScrollViewer.Resources>
        <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">100</sys:Double>
    </ScrollViewer.Resources>
</ScrollViewer>

回答by DuckMaestro

Kent's answer can also be applied to easily allscrollbars in your application by placing it in your App.xamlresources, and by specifying the horizontal height key as well.

通过将 Kent 的答案放置在资源中并指定水平高度键,也可以轻松地将其应用于应用程序中的所有滚动条App.xaml

<Application
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    ...
>
    <Application.Resources>
        <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">50</sys:Double>
        <sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">50</sys:Double>
    </Application.Resources>
</Application>

回答by Kulvir

Here is a XAML solution:

这是一个 XAML 解决方案:

<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
    <Setter Property="Stylus.IsFlicksEnabled" Value="True" />
    <Style.Triggers>
        <Trigger Property="Orientation" Value="Horizontal">
            <Setter Property="Height" Value="40" />
            <Setter Property="MinHeight" Value="40" />
        </Trigger>
        <Trigger Property="Orientation" Value="Vertical">
            <Setter Property="Width" Value="40" />
            <Setter Property="MinWidth" Value="40" />
        </Trigger>
    </Style.Triggers>
</Style>

回答by mihails.kuzmins

And if you don't want to use XAML, you can do it in the Application's constructor, e.g.

如果你不想使用 XAML,你可以在Application的构造函数中进行,例如

using System.Windows;

public partial class App
{
    public App()
    {
        Resources.Add(SystemParameters.VerticalScrollBarWidthKey, 50d);
        Resources.Add(SystemParameters.HorizontalScrollBarHeightKey, 50d);
    }
}