两个问题:
- 如何在 WPF 中的 ScrollBar 上禁用拖动拇指?
- 有没有办法限制拖动拇指的位置?像 LargeChange 还是 SmallChange?
编辑 ScrollBar 控件的模板并将 Thumb 的 IsEnabled 属性设置为 false
不确定您是否可以直接从代码或 XAML 执行此操作,但您可以将 2 个新 DP 添加到继承 ScrollBar 类的控件,然后更改模板以具有此新功能
也许它对某人有用如果你想通过两种方式禁用拖动拇指:
例子:
<Style TargetType="{x:Type ScrollBar}">
<Setter Property="Background" Value="{StaticResource BackgroundColor}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Grid x:Name="Bg" SnapsToDevicePixels="true">
<Grid.RowDefinitions>
<RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>
<RowDefinition Height="0.00001*"/>
<RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>
</Grid.RowDefinitions>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Row="1" />
<RepeatButton Grid.Row="0" Command="ScrollBar.PageUpCommand" Style="{StaticResource ScrollBarButton}" Content="M 0 4 L 8 4 L 4 0 Z"/>
<Rectangle Grid.Row="1" VerticalAlignment="Top" x:Name="ThumbReplacer" Fill="{DynamicResource ScrollColor}"/>
<RepeatButton Grid.Row="2" Command="ScrollBar.PageDownCommand" Style="{StaticResource ScrollBarButton}" Content="M 0 0 L 4 4 L 8 0 Z"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>