How to increase scrollbar width in WPF ScrollViewer?

China☆狼群 提交于 2019-11-26 13:02:31

问题


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?

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.


回答1:


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>



回答2:


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>



回答3:


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>


来源:https://stackoverflow.com/questions/1321247/how-to-increase-scrollbar-width-in-wpf-scrollviewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!