代码之家  ›  专栏  ›  技术社区  ›  JohnIdol

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

  •  44
  • JohnIdol  · 技术社区  · 16 年前

    请注意,我不想更改设备上所有滚动条的宽度(可以通过窗口设置更改),只想更改我应用程序中的滚动条。

    4 回复  |  直到 12 年前
        1
  •  71
  •   Tim Cooper    14 年前

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

    <ScrollViewer>
        <ScrollViewer.Resources>
            <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">100</sys:Double>
        </ScrollViewer.Resources>
    </ScrollViewer>
    
        2
  •  29
  •   DuckMaestro    12 年前

    通过将滚动条放置在应用程序中 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>
    
        3
  •  24
  •   Kulvir    13 年前

    以下是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>
    
        4
  •  2
  •   mihails.kuzmins    5 年前

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

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