1. 程式人生 > >WPF-自定義滾動條ScrollBar

WPF-自定義滾動條ScrollBar

<!--
滾動條的基本構成。
有了這些,就可以定義自己的滾動條了。
-->
<Style TargetType="{x:Type ScrollBar}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollBar}">
                <StackPanel>
                    <!--上按鈕-->
                    <RepeatButton HorizontalAlignment="Center" VerticalAlignment="Top" Command="ScrollBar.LineUpCommand" Content="^"/>
                    <Track  x:Name="PART_Track" IsDirectionReversed="True" Height="100">
                        <Track.DecreaseRepeatButton>
                            <!--上空白-->
                            <RepeatButton Command="ScrollBar.PageUpCommand" />
                        </Track.DecreaseRepeatButton>
                        <Track.Thumb>
                            <!--滑塊-->
                            <Thumb Background="Black"/>
                        </Track.Thumb>
                        <Track.IncreaseRepeatButton>
                            <!--下空白-->
                            <RepeatButton Command="ScrollBar.PageDownCommand" />
                        </Track.IncreaseRepeatButton>
                    </Track>
                    <!--下按鈕-->
                    <RepeatButton HorizontalAlignment="Center" VerticalAlignment="Top" Command="ScrollBar.LineDownCommand" Content="v"/>
                </StackPanel>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
轉自:http://www.luacloud.com/2011/wpf-custom-scrollbar-style.html