zoukankan      html  css  js  c++  java
  • [WPF] 默认滚动条,通过附加属性和样式实现自定义

    效果图:

    Xaml文件:

    <DockPanel Margin="10">
        <WrapPanel DockPanel.Dock="Top" Margin="10">
            <DockPanel Margin="6">
                <TextBlock VerticalAlignment="Center">滚动条样式:</TextBlock>
                <RadioButton x:Name="radio_inline" Click="OnRadioClick">Inline</RadioButton>
                <RadioButton x:Name="radio_overlay" Click="OnRadioClick" IsChecked="True" Margin="10 0 0 0">Overlay</RadioButton>
            </DockPanel>
            <DockPanel Margin="6">
                <TextBlock VerticalAlignment="Center">内容高度:</TextBlock>
                <TextBox MinWidth="60" Text="{Binding Height,ElementName=rec,UpdateSourceTrigger=PropertyChanged}" />
            </DockPanel>
            <DockPanel Margin="6">
                <TextBlock VerticalAlignment="Center">滑块窄:</TextBlock>
                <TextBox MinWidth="60" Text="{Binding Path=(pp:ScrollBarElement.ThumbWidth),ElementName=scroll}" />
            </DockPanel>
            <DockPanel Margin="6">
                <TextBlock VerticalAlignment="Center">滑块窄 :Hover:</TextBlock>
                <TextBox MinWidth="60" Text="{Binding Path=(pp:ScrollBarElement.HoverThumbWidth),ElementName=scroll}" />
            </DockPanel>
            <DockPanel Margin="6">
                <TextBlock VerticalAlignment="Center">滑块最小长度:</TextBlock>
                <TextBox MinWidth="60" Text="{Binding Path=(pp:ScrollBarElement.ThumbMinLength),ElementName=scroll}" />
            </DockPanel>
            <DockPanel Margin="6">
                <TextBlock VerticalAlignment="Center">滑块圆角:</TextBlock>
                <TextBox MinWidth="60" Text="{Binding Path=(pp:ScrollBarElement.ThumbRadius),ElementName=scroll}" />
            </DockPanel>
            <DockPanel Margin="6">
                <TextBlock VerticalAlignment="Center">滑块圆角 :Hover:</TextBlock>
                <TextBox MinWidth="60" Text="{Binding Path=(pp:ScrollBarElement.HoverThumbRadius),ElementName=scroll}" />
            </DockPanel>
        </WrapPanel>
        <ScrollViewer x:Name="scroll" Style="{StaticResource PP.Styles.ScrollViewer.Overlay}" HorizontalScrollBarVisibility="Auto" Margin="10">
            <Rectangle x:Name="rec" Width="1280" Height="720" Fill="{StaticResource drawingBrush}" />
        </ScrollViewer>
    </DockPanel>

    通过样式和修改附加属性,实现各种效果;

    新增的附加属性有:

    1、ScrollBarElement.Background,滚动条的背景色,与ScrollViewer.Background区分开;

    2、ThumbFill,拖动块填充颜色;

    3、ThumbHoverFill,鼠标悬浮时拖动块填充颜色;

    4、ThumbPressFill,鼠标按压时拖动块填充颜色;

    5、ThumbWidth,拖动块宽度(横向时指高度);

    6、HoverThumbWidth,鼠标悬浮时拖动块宽度(横向时指高度);

    7、ThumbRadius,拖动块圆角大小;

    8、HoverThumbRadius,鼠标悬浮时拖动块圆角大小;

    9、ThumbMinLength,拖动块最小高度(横向时指宽度);

    代码已上传至GitHub:https://github.com/LowPlayer/PP.Wpf

  • 相关阅读:
    剑指offer-二维数组中的查找 java实现
    Matlab2015b激活失效解决办法
    解决ueditor在多图上传的时候偶尔抽风,图片丢失或者乱序
    用.net正则去除所有的html源码或者提取出图片地址以及存数据库时的符号替换(如富文本编辑器)
    DropDownList的动态绑定方法(两种)
    Ueditor使用说明(包括设置其可编辑不可编辑)
    用webuploader上传图片并预览(上传文件)
    .net日期控件(全.net)
    代码注释
    面向对象的概念
  • 原文地址:https://www.cnblogs.com/pumbaa/p/14548651.html
Copyright © 2011-2022 走看看