110,571
社区成员
发帖
与我相关
我的任务
分享
<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>
<ScrollViewer.Resources>
<s:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">5</s:Double>
<s:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">5</s:Double>
<s:Double x:Key="{x:Static SystemParameters.VerticalScrollBarThumbHeightKey}">10</s:Double>
<s:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarThumbWidthKey}">10</s:Double>
</ScrollViewer.Resources>
<ScrollViewer HorizontalScrollBarVisibility="Auto" xmlns:s="clr-namespace:System;assembly=mscorlib">
<ScrollViewer.Resources>
<s:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">10</s:Double>
<s:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">10</s:Double>
<s:Double x:Key="{x:Static SystemParameters.VerticalScrollBarThumbHeightKey}">100</s:Double>
<s:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarThumbWidthKey}">100</s:Double>
<Style TargetType="{x:Type ScrollBar}">
<Style.Triggers>
<Trigger Property="Orientation" Value="Horizontal">
<Setter Property="Width" Value="Auto"/>
<Setter Property="Height" Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarThumbHeightKey}}"/>
</Trigger>
</Style.Triggers>
</Style>
</ScrollViewer.Resources>
<Canvas Width="600" Height="600"/>
</ScrollViewer>
你试下下这段样式代码,这是由博客园上第二种方法修改而来的,他用的是固定值100,我这里用系统资源VerticalScrollBarThumbHeightKey,你会发现,通过前面的“<s:Double x:Key="{x:Static SystemParameters.VerticalScrollBarThumbHeightKey}">100</s:Double>”的修改是有效的,但是当你把DynamicResource改为了StaticResource后,就无效了,这是资源字典引用的一个区别,静态引用的话,就无法通过运行时修改来改变它绑定的值。故而推测你的那个Thumb的宽度、高度是静态资源引用,非动态的引用。因为无法看到原始xaml文件定义,所以这里只能是推测,希望这个说法你可以接受。