How to increase scrollbar width in WPF ScrollViewer?

前端 未结 4 1254
臣服心动
臣服心动 2020-12-01 04:33

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

相关标签:
4条回答
  • 2020-12-01 04:48

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

    <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>
    
    0 讨论(0)
  • 2020-12-01 04:58

    Here is a XAML solution:

    <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>
    
    0 讨论(0)
  • 2020-12-01 05:06

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

    using System.Windows;
    
    public partial class App
    {
        public App()
        {
            Resources.Add(SystemParameters.VerticalScrollBarWidthKey, 50d);
            Resources.Add(SystemParameters.HorizontalScrollBarHeightKey, 50d);
        }
    }
    
    0 讨论(0)
  • 2020-12-01 05:15

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

    <ScrollViewer>
        <ScrollViewer.Resources>
            <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">100</sys:Double>
        </ScrollViewer.Resources>
    </ScrollViewer>
    
    0 讨论(0)
提交回复
热议问题