自定义ScrollViewer样式

<Grid.Resources>
                <SolidColorBrush x:Key="NormalColor">#898E9A</SolidColorBrush>

                <SolidColorBrush x:Key="HighlightColor">#6C7079</SolidColorBrush>

                <SolidColorBrush x:Key="PressedColor">#222426</SolidColorBrush>

                <SolidColorBrush x:Key="BorderColor">#90A3B9</SolidColorBrush>

                <SolidColorBrush x:Key="BackColor">#414651</SolidColorBrush>

 

                <Style x:Key="stBorder" TargetType="Border">

                    <Setter Property="BorderBrush" Value="{StaticResource BorderColor}"/>

                    <Setter Property="BorderThickness" Value="1"/>

                    <Setter Property="Background" Value="{StaticResource NormalColor}"/>

                    <Setter Property="CornerRadius" Value="3"/>

                </Style>

                <Style x:Key="stBackBorder" TargetType="Border">

                    <Setter Property="BorderBrush" Value="{StaticResource BorderColor}"/>

                    <Setter Property="BorderThickness" Value="1"/>

                    <Setter Property="Background" Value="{StaticResource BackColor}"/>

                    <Setter Property="CornerRadius" Value="3"/>

                </Style>

 

                <Style x:Key="stRepeatBtn" TargetType="RepeatButton">

                    <Setter Property="SnapsToDevicePixels" Value="True"/>

                    <Setter Property="OverridesDefaultStyle" Value="true"/>

                    <Setter Property="Focusable" Value="false"/>

                    <Setter Property="Template">

                        <Setter.Value>

                            <ControlTemplate TargetType="RepeatButton">

                                <Border Name="bd"

                                Style="{StaticResource stBorder}">

                                    <Path

                                HorizontalAlignment="Center"

                                VerticalAlignment="Center"

                                Fill="White"

                                Data="{Binding Path=Content,RelativeSource={RelativeSource TemplatedParent}}" />

 

                                </Border>

                                <ControlTemplate.Triggers>

                                    <Trigger Property="IsMouseOver" Value="true">

                                        <Setter TargetName="bd" Property="Background" Value="{StaticResource HighlightColor}"/>

                                    </Trigger>

                                    <Trigger Property="IsPressed" Value="true">

                                        <Setter TargetName="bd" Property="Background" Value="{StaticResource PressedColor}"/>

                                    </Trigger>

                                </ControlTemplate.Triggers>

                            </ControlTemplate>

                        </Setter.Value>

                    </Setter>

                </Style>

 

                <Style x:Key="stScrollBtn" TargetType="RepeatButton">

                    <Setter Property="SnapsToDevicePixels" Value="True"/>

                    <Setter Property="OverridesDefaultStyle" Value="true"/>

                    <Setter Property="IsTabStop" Value="false"/>

                    <Setter Property="Focusable" Value="false"/>

                    <Setter Property="Template">

                        <Setter.Value>

                            <ControlTemplate TargetType="RepeatButton">

                                <Border Background="Transparent" />

                            </ControlTemplate>

                        </Setter.Value>

                    </Setter>

                </Style>

 

                <Style x:Key="stThumb" TargetType="{x:Type Thumb}">

                    <Setter Property="SnapsToDevicePixels" Value="True"/>

                    <Setter Property="OverridesDefaultStyle" Value="true"/>

                    <Setter Property="IsTabStop" Value="false"/>

                    <Setter Property="Focusable" Value="false"/>

                    <Setter Property="Template">

                        <Setter.Value>

                            <ControlTemplate TargetType="{x:Type Thumb}">

                                <Border Name="bd" Style="{StaticResource stBorder}"></Border>

                                <ControlTemplate.Triggers>

                                    <Trigger Property="IsDragging" Value="true">

                                        <Setter TargetName="bd" Property="Background" Value="{StaticResource PressedColor}"></Setter>

                                    </Trigger>

                                    <Trigger Property="IsMouseOver" Value="true">

                                        <Setter TargetName="bd" Property="Background" Value="{StaticResource HighlightColor}"></Setter>

                                    </Trigger>

                                </ControlTemplate.Triggers>

                            </ControlTemplate>

                        </Setter.Value>

                    </Setter>

                </Style>

 

                <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">

                    <Border Style="{StaticResource stBackBorder}">

                        <Grid>

                            <Grid.RowDefinitions>

                                <RowDefinition/>

                                <RowDefinition MaxHeight="18"/>

                                <RowDefinition MaxHeight="18"/>

                            </Grid.RowDefinitions>

                            <Border

                      Grid.RowSpan="3"

                      CornerRadius="2" />

                            <RepeatButton

                      Grid.Row="1"                          

                      Style="{StaticResource stRepeatBtn}"

                      Height="18"

                      Command="ScrollBar.LineUpCommand"

                      Content="M 0 4 L 8 4 L 4 0 Z" />

                            <Track

                      Name="PART_Track"

                      Grid.Row="0"

                      IsDirectionReversed="true">

                                <Track.DecreaseRepeatButton>

                                    <RepeatButton

                              Style="{StaticResource stScrollBtn}"

                              Command="ScrollBar.PageUpCommand" />

                                </Track.DecreaseRepeatButton>

                                <Track.Thumb>

                                    <Thumb

                              Style="{StaticResource stThumb}"

                              Margin="1,0,1,0"  />

                                </Track.Thumb>

                                <Track.IncreaseRepeatButton>

                                    <RepeatButton

                              Style="{StaticResource stScrollBtn}"

                              Command="ScrollBar.PageDownCommand" />

                                </Track.IncreaseRepeatButton>

                            </Track>

                            <RepeatButton

                      Grid.Row="3"

                      Style="{StaticResource stRepeatBtn}"

                      Height="18"

                      Command="ScrollBar.LineDownCommand"

                      Content="M 0 0 L 4 4 L 8 0 Z"/>

                        </Grid>

                    </Border>

                </ControlTemplate>

                <ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">

                    <Border Style="{StaticResource stBackBorder}">

                        <Grid >

                            <Grid.ColumnDefinitions>

                                <ColumnDefinition/>

                                <ColumnDefinition MaxWidth="18"/>

                                <ColumnDefinition MaxWidth="18"/>

                            </Grid.ColumnDefinitions>

                            <Border

                      Grid.ColumnSpan="3"

                      CornerRadius="2"  />

                            <RepeatButton

                      Grid.Column="1"                          

                      Style="{StaticResource stRepeatBtn}"

                      Width="18"

                      Command="ScrollBar.LineLeftCommand"

                      Content="M 4 0 L 4 8 L 0 4 Z" />

                            <Track

                      Name="PART_Track"

                      Grid.Column="0"

                      IsDirectionReversed="False">

                                <Track.DecreaseRepeatButton>

                                    <RepeatButton

                              Style="{StaticResource stScrollBtn}"

                              Command="ScrollBar.PageLeftCommand" />

                                </Track.DecreaseRepeatButton>

                                <Track.Thumb>

                                    <Thumb

                              Style="{StaticResource stThumb}"

                              Margin="0,1,0,1"   />

                                </Track.Thumb>

                                <Track.IncreaseRepeatButton>

                                    <RepeatButton

                              Style="{StaticResource stScrollBtn}"

                              Command="ScrollBar.PageRightCommand" />

                                </Track.IncreaseRepeatButton>

                            </Track>

                            <RepeatButton

                      Grid.Column="2"

                      Style="{StaticResource stRepeatBtn}"

                      Width="18"

                      Command="ScrollBar.LineRightCommand"

                      Content="M 0 0 L 4 4 L 0 8 Z"/>

                        </Grid>

                    </Border>

                </ControlTemplate>

 

                <Style TargetType="{x:Type BaseControls:MyScrollViewer}">

                    <Setter Property="OverridesDefaultStyle" Value="True"/>

                    <Setter Property="Template">

                        <Setter.Value>

                            <ControlTemplate TargetType="{x:Type ScrollViewer}">

                                <Grid Background="{StaticResource BackColor}">

                                    <Grid.ColumnDefinitions>

                                        <ColumnDefinition/>

                                        <ColumnDefinition Width="Auto"/>

                                    </Grid.ColumnDefinitions>

                                    <Grid.RowDefinitions>

                                        <RowDefinition/>

                                        <RowDefinition Height="Auto"/>

                                    </Grid.RowDefinitions>

 

                                    <ScrollContentPresenter/>

 

                                    <ScrollBar  Name="PART_VerticalScrollBar"

                                        Grid.Column="1"

                                        Value="{TemplateBinding VerticalOffset}"

                                        Maximum="{TemplateBinding ScrollableHeight}"

                                        ViewportSize="{TemplateBinding ViewportHeight}"

                                        Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"

                                        Template="{StaticResource VerticalScrollBar}"/>

                                    <ScrollBar  Name="PART_HorizontalScrollBar"

                                        Orientation="Horizontal"

                                        Grid.Row="1"

                                        Value="{TemplateBinding HorizontalOffset}"

                                        Maximum="{TemplateBinding ScrollableWidth}"

                                        ViewportSize="{TemplateBinding ViewportWidth}"

                                        Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"

                                        Template="{StaticResource HorizontalScrollBar}"/>

 

                                </Grid>

                            </ControlTemplate>

                        </Setter.Value>

                    </Setter>

                </Style>


            </Grid.Resources>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值