Joh*_*dol 32 wpf scrollbar scrollviewer width
我正在小型设备上使用触摸屏,滚动条的自定义宽度并不好,因为我的要求之一就是手指手势都需要一切.
如何设置WPF ScrollViewer滚动条的宽度?
请注意,我不想更改设备上所有滚动条的宽度(可以通过Windows设置) - 只有我的应用程序中的滚动条.
Ken*_*art 56
该ScrollBar模板伸出为系统参数,以确定其宽度/高度(取决于方向).因此,您可以覆盖这些参数:
<ScrollViewer>
<ScrollViewer.Resources>
<sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">100</sys:Double>
</ScrollViewer.Resources>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
小智 20
这是一个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>
Run Code Online (Sandbox Code Playgroud)
Duc*_*tro 19
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>
Run Code Online (Sandbox Code Playgroud)
如果您不想使用 XAML,您可以在 的Application构造函数中执行此操作,例如
using System.Windows;
public partial class App
{
public App()
{
Resources.Add(SystemParameters.VerticalScrollBarWidthKey, 50d);
Resources.Add(SystemParameters.HorizontalScrollBarHeightKey, 50d);
}
}
Run Code Online (Sandbox Code Playgroud)