我正在写(注销)样式ScrollBar
。
问题是一个无法理解的空白空间,它等于标准宽度ScrollBar
。如何删除它?
款式:
<Window.Resources>
<Style x:Key="ScrollBarTrackThumb" TargetType="{x:Type Thumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Grid x:Name="Grid">
<Rectangle HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Width="Auto"
Height="Auto"
Fill="Transparent" />
<Border x:Name="CornerScrollBarRectangle"
CornerRadius="7"
Background="{TemplateBinding Background}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Tag" Value="Horizontal">
<Setter TargetName="CornerScrollBarRectangle" Property="Width" Value="Auto" />
<Setter TargetName="CornerScrollBarRectangle" Property="Height" Value="6" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ScrollBar}">
<Setter Property="Stylus.IsFlicksEnabled" Value="True" />
<Setter Property="Foreground" Value="#ffff8000" />
<Setter Property="Background" Value="#786441A4" />
<Setter Property="Width" Value="7"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Grid x:Name="GridRoot" Width="{TemplateBinding Width}"
Background="{TemplateBinding Background}"
HorizontalAlignment="Right">
<Track x:Name="PART_Track"
IsDirectionReversed="true"
Focusable="false">
<Track.Thumb>
<Thumb x:Name="Thumb"
Background="{TemplateBinding Foreground}"
Style="{DynamicResource ScrollBarTrackThumb}"/>
</Track.Thumb>
</Track>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ScrollBarBlink}" Value="1">
<Setter Property="Foreground" Value="#ff6441A4"/>
<Setter Property="Background" Value="#ccff8000"/>
</DataTrigger>
<DataTrigger Binding="{Binding ScrollBarBlink}" Value="2">
<Setter Property="Foreground" Value="#ffff8000"/>
<Setter Property="Background" Value="#cc6441A4"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
自己ScrollViewer
:
<ScrollViewer Name="_scrollViewer" VerticalScrollBarVisibility="Visible">
...
</ScrollViewer>
如果您查看标准样式
ScrollBar
,您可以在那里找到这一行:这个动态资源的背后是从操作系统设置中获取滚动条的宽度。
整个问题在于它。只需覆盖
MinWidth
您的新样式。