2
當我不再需要它的拇指時,我無法弄清楚如何更改ScrollBar Opactity。基於Thumb可見性的WPF ScrollBar不透明度
換句話說:我想讓ScrollViewer的屬性VerticalScrollBarVisibility像Auto,但ScrollViewer的內容應該保留它的大小。我必須考慮到ScrollBar的風格必須應用於帶有內置ScrollViewer的第三方控件。
這是我的代碼。我試圖對Thumb的IsVisible觸發器做出反應,但沒有成功。
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border x:Name="ScrollBarThumbBorder" CornerRadius="4" />
</ControlTemplate>
</Setter.Value>
</Setter>
<!--<Style.Triggers>
<Trigger Property="IsVisible" Value="False">
<Setter Property="Opacity" Value="0.3" />
</Trigger>
</Style.Triggers>-->
<ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
<Border CornerRadius="4">
<Track
Name="PART_Track"
IsDirectionReversed="true">
<Track.DecreaseRepeatButton>
<RepeatButton
Style="{StaticResource ScrollBarPageButton}"
Command="ScrollBar.PageUpCommand" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" />
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton
Style="{StaticResource ScrollBarPageButton}"
Command="ScrollBar.PageDownCommand" />
</Track.IncreaseRepeatButton>
</Track>
</Border>
<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Style.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Width" Value="10"/>
<Setter Property="Height" Value="Auto" />
<Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
</Trigger>
</Style.Triggers>