设置WPF滚动条的宽度

来源:转载

方法1:改写SystemParameters类的属性

WPF滚动条的宽度参数存储在SystemParameters中的VerticalScrollBarWidthKey,和HorizontalScrollBarHeightKey属性中,那么很简单定义一个动态资源在其范围内改变这个参数就可以

       <ScrollViewer HorizontalScrollBarVisibility="Auto"                      xmlns:sys="clr-namespace:System;assembly=mscorlib">

            <ScrollViewer.Resources>

                <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">100</sys:Double>

                <sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">100</sys:Double>

            </ScrollViewer.Resources>

            <Button Width="400" Height="400">aaa</Button>

        </ScrollViewer>

方法2:定义样式

在ScrollViewer中定义一个针对ScrollBar类的样式,这样ScrollViewer中的ScrollBar的相应属性会被设置

       <ScrollViewer HorizontalScrollBarVisibility="Auto">

            <ScrollViewer.Resources>

                <Style TargetType="{x:Type ScrollBar}">

                    <Style.Triggers>

                        <Trigger Property="Orientation" Value="Horizontal">

                            <Setter Property="Width" Value="Auto"/>

                            <Setter Property="Height" Value="100" />

                        </Trigger>

                        <Trigger Property="Orientation" Value="Vertical">

                            <Setter Property="Width" Value="100"/>

                            <Setter Property="Height" Value="Auto" />

                        </Trigger>

                    </Style.Triggers>

                </Style>

            </ScrollViewer.Resources>

                <Button Width="400" Height="400">aaa</Button>

        </ScrollViewer>

两者运行后效果一样:

本文来自_Mgen的博客,原文地址:http://www.cnblogs.com/mgen/archive/2011/06/24/2088861.html


分享给朋友:
您可能感兴趣的文章:
随机阅读: