ScrollViewer.xaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  2. <Style TargetType="{x:Type ScrollViewer}">
  3. <Setter Property="FocusVisualStyle" Value="{x:Null}" />
  4. </Style>
  5. <Style x:Key="ScrollThumbs" TargetType="{x:Type Thumb}">
  6. <Setter Property="Template">
  7. <Setter.Value>
  8. <ControlTemplate TargetType="{x:Type Thumb}">
  9. <Grid x:Name="Grid">
  10. <Rectangle
  11. Width="Auto"
  12. Height="Auto"
  13. HorizontalAlignment="Stretch"
  14. VerticalAlignment="Stretch"
  15. Fill="Transparent" />
  16. <Border
  17. x:Name="Rectangle1"
  18. Width="Auto"
  19. Height="Auto"
  20. HorizontalAlignment="Stretch"
  21. VerticalAlignment="Stretch"
  22. Background="{TemplateBinding Background}"
  23. CornerRadius="5" />
  24. </Grid>
  25. <ControlTemplate.Triggers>
  26. <Trigger Property="Tag" Value="Horizontal">
  27. <Setter TargetName="Rectangle1" Property="Width" Value="Auto" />
  28. <Setter TargetName="Rectangle1" Property="Height" Value="7" />
  29. </Trigger>
  30. </ControlTemplate.Triggers>
  31. </ControlTemplate>
  32. </Setter.Value>
  33. </Setter>
  34. </Style>
  35. <!-- ScrollBars -->
  36. <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
  37. <Setter Property="Stylus.IsFlicksEnabled" Value="false" />
  38. <Setter Property="Foreground" Value="LightGray" />
  39. <Setter Property="Background" Value="Transparent" />
  40. <Setter Property="Width" Value="7" />
  41. <Setter Property="Template">
  42. <Setter.Value>
  43. <ControlTemplate TargetType="{x:Type ScrollBar}">
  44. <Grid
  45. x:Name="GridRoot"
  46. Width="{TemplateBinding Width}"
  47. Background="{TemplateBinding Background}">
  48. <Grid.RowDefinitions>
  49. <RowDefinition Height="0.00001*" />
  50. </Grid.RowDefinitions>
  51. <Track
  52. x:Name="PART_Track"
  53. Grid.Row="0"
  54. Focusable="false"
  55. IsDirectionReversed="true">
  56. <Track.Thumb>
  57. <Thumb
  58. x:Name="Thumb"
  59. Background="{TemplateBinding Foreground}"
  60. Style="{DynamicResource ScrollThumbs}" />
  61. </Track.Thumb>
  62. <Track.IncreaseRepeatButton>
  63. <RepeatButton
  64. x:Name="PageUp"
  65. Command="ScrollBar.PageDownCommand"
  66. Focusable="false"
  67. Opacity="0" />
  68. </Track.IncreaseRepeatButton>
  69. <Track.DecreaseRepeatButton>
  70. <RepeatButton
  71. x:Name="PageDown"
  72. Command="ScrollBar.PageUpCommand"
  73. Focusable="false"
  74. Opacity="0" />
  75. </Track.DecreaseRepeatButton>
  76. </Track>
  77. </Grid>
  78. <ControlTemplate.Triggers>
  79. <Trigger SourceName="Thumb" Property="IsMouseOver" Value="true">
  80. <Setter TargetName="Thumb" Property="Background" Value="{DynamicResource ButtonSelectBrush}" />
  81. </Trigger>
  82. <Trigger SourceName="Thumb" Property="IsDragging" Value="true">
  83. <Setter TargetName="Thumb" Property="Background" Value="{DynamicResource DarkBrush}" />
  84. </Trigger>
  85. <Trigger Property="IsEnabled" Value="false">
  86. <Setter TargetName="Thumb" Property="Visibility" Value="Collapsed" />
  87. </Trigger>
  88. <Trigger Property="Orientation" Value="Horizontal">
  89. <Setter TargetName="GridRoot" Property="LayoutTransform">
  90. <Setter.Value>
  91. <RotateTransform Angle="-90" />
  92. </Setter.Value>
  93. </Setter>
  94. <Setter TargetName="PART_Track" Property="LayoutTransform">
  95. <Setter.Value>
  96. <RotateTransform Angle="-90" />
  97. </Setter.Value>
  98. </Setter>
  99. <Setter Property="Width" Value="Auto" />
  100. <Setter Property="Height" Value="12" />
  101. <Setter TargetName="Thumb" Property="Tag" Value="Horizontal" />
  102. <Setter TargetName="PageDown" Property="Command" Value="ScrollBar.PageLeftCommand" />
  103. <Setter TargetName="PageUp" Property="Command" Value="ScrollBar.PageRightCommand" />
  104. </Trigger>
  105. </ControlTemplate.Triggers>
  106. </ControlTemplate>
  107. </Setter.Value>
  108. </Setter>
  109. </Style>
  110. <Style x:Key="AutoHideScrollBarThumb" TargetType="Thumb">
  111. <Setter Property="OverridesDefaultStyle" Value="True" />
  112. <Setter Property="IsTabStop" Value="False" />
  113. <Setter Property="Template">
  114. <Setter.Value>
  115. <ControlTemplate TargetType="{x:Type Thumb}">
  116. <Grid>
  117. <Border Background="#808080" />
  118. </Grid>
  119. </ControlTemplate>
  120. </Setter.Value>
  121. </Setter>
  122. </Style>
  123. <Style x:Key="VerticalScrollBarPageButton" TargetType="{x:Type RepeatButton}">
  124. <Setter Property="OverridesDefaultStyle" Value="True" />
  125. <Setter Property="Background" Value="Transparent" />
  126. <Setter Property="Focusable" Value="False" />
  127. <Setter Property="IsTabStop" Value="False" />
  128. <Setter Property="Opacity" Value="0.2" />
  129. <Setter Property="Template">
  130. <Setter.Value>
  131. <ControlTemplate TargetType="{x:Type RepeatButton}">
  132. <Rectangle
  133. Width="{TemplateBinding Width}"
  134. Height="{TemplateBinding Height}"
  135. Fill="{TemplateBinding Background}" />
  136. </ControlTemplate>
  137. </Setter.Value>
  138. </Setter>
  139. </Style>
  140. <Style x:Key="VerticalScrollBarPageButton2" TargetType="{x:Type RepeatButton}">
  141. <Setter Property="OverridesDefaultStyle" Value="True" />
  142. <Setter Property="Background" Value="Transparent" />
  143. <Setter Property="Focusable" Value="False" />
  144. <Setter Property="IsTabStop" Value="False" />
  145. <Setter Property="Opacity" Value="0" />
  146. <Setter Property="Template">
  147. <Setter.Value>
  148. <ControlTemplate TargetType="{x:Type RepeatButton}">
  149. <Rectangle
  150. Width="0"
  151. Height="0"
  152. Fill="#90000000" />
  153. </ControlTemplate>
  154. </Setter.Value>
  155. </Setter>
  156. </Style>
  157. <Style x:Key="AutoHideScrollBar" TargetType="{x:Type ScrollBar}">
  158. <Setter Property="Stylus.IsPressAndHoldEnabled" Value="False" />
  159. <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
  160. <Setter Property="Background" Value="Transparent" />
  161. <Setter Property="Margin" Value="2,1,1,6" />
  162. <Setter Property="Width" Value="10" />
  163. <Setter Property="MinWidth" Value="5" />
  164. <Setter Property="Opacity" Value="0.1" />
  165. <Setter Property="Template">
  166. <Setter.Value>
  167. <ControlTemplate TargetType="{x:Type ScrollBar}">
  168. <Grid x:Name="Bg" SnapsToDevicePixels="True">
  169. <Grid.RowDefinitions>
  170. <RowDefinition Height="Auto" />
  171. <RowDefinition Height="*" />
  172. <RowDefinition Height="Auto" />
  173. </Grid.RowDefinitions>
  174. <RepeatButton Grid.Row="0" Style="{StaticResource VerticalScrollBarPageButton2}" />
  175. <Track
  176. x:Name="PART_Track"
  177. Grid.Row="1"
  178. IsDirectionReversed="True"
  179. IsEnabled="{TemplateBinding IsMouseOver}">
  180. <Track.DecreaseRepeatButton>
  181. <RepeatButton Command="{x:Static ScrollBar.PageUpCommand}" Style="{StaticResource VerticalScrollBarPageButton}" />
  182. </Track.DecreaseRepeatButton>
  183. <Track.IncreaseRepeatButton>
  184. <RepeatButton Command="{x:Static ScrollBar.PageDownCommand}" Style="{StaticResource VerticalScrollBarPageButton}" />
  185. </Track.IncreaseRepeatButton>
  186. <Track.Thumb>
  187. <Thumb Style="{StaticResource AutoHideScrollBarThumb}" />
  188. </Track.Thumb>
  189. </Track>
  190. <RepeatButton Grid.Row="2" Style="{StaticResource VerticalScrollBarPageButton2}" />
  191. </Grid>
  192. </ControlTemplate>
  193. </Setter.Value>
  194. </Setter>
  195. </Style>
  196. <Style x:Key="AutoHideScrollViewer" TargetType="{x:Type ScrollViewer}">
  197. <Setter Property="FocusVisualStyle" Value="{x:Null}" />
  198. <Setter Property="BorderBrush" Value="LightGray" />
  199. <Setter Property="BorderThickness" Value="0" />
  200. <Setter Property="Padding" Value="0" />
  201. <Setter Property="Template">
  202. <Setter.Value>
  203. <ControlTemplate TargetType="{x:Type ScrollViewer}">
  204. <Border
  205. x:Name="Whole"
  206. BorderBrush="{TemplateBinding BorderBrush}"
  207. BorderThickness="{TemplateBinding BorderThickness}"
  208. SnapsToDevicePixels="True">
  209. <Grid Background="{TemplateBinding Background}">
  210. <ScrollContentPresenter
  211. Margin="{TemplateBinding Padding}"
  212. ContentTemplate="{TemplateBinding ContentTemplate}"
  213. Cursor="{TemplateBinding Cursor}" />
  214. <ScrollBar
  215. x:Name="PART_VerticalScrollBar"
  216. HorizontalAlignment="Right"
  217. Maximum="{TemplateBinding ScrollableHeight}"
  218. Orientation="Vertical"
  219. Style="{StaticResource AutoHideScrollBar}"
  220. ViewportSize="{TemplateBinding ViewportHeight}"
  221. Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
  222. Value="{TemplateBinding VerticalOffset}" />
  223. </Grid>
  224. </Border>
  225. <ControlTemplate.Triggers>
  226. <EventTrigger RoutedEvent="ScrollChanged">
  227. <BeginStoryboard>
  228. <Storyboard>
  229. <DoubleAnimation
  230. Storyboard.TargetName="PART_VerticalScrollBar"
  231. Storyboard.TargetProperty="Opacity"
  232. To="0.8"
  233. Duration="0:0:1" />
  234. <DoubleAnimation
  235. BeginTime="0:0:1"
  236. Storyboard.TargetName="PART_VerticalScrollBar"
  237. Storyboard.TargetProperty="Opacity"
  238. To="0.1"
  239. Duration="0:0:1" />
  240. </Storyboard>
  241. </BeginStoryboard>
  242. </EventTrigger>
  243. <EventTrigger RoutedEvent="MouseEnter" SourceName="Whole">
  244. <BeginStoryboard>
  245. <Storyboard>
  246. <DoubleAnimation
  247. Storyboard.TargetName="PART_VerticalScrollBar"
  248. Storyboard.TargetProperty="Opacity"
  249. To="0.8"
  250. Duration="0:0:0.7" />
  251. </Storyboard>
  252. </BeginStoryboard>
  253. </EventTrigger>
  254. <EventTrigger RoutedEvent="MouseLeave" SourceName="Whole">
  255. <BeginStoryboard>
  256. <Storyboard>
  257. <DoubleAnimation
  258. Storyboard.TargetName="PART_VerticalScrollBar"
  259. Storyboard.TargetProperty="Opacity"
  260. To="0.1"
  261. Duration="0:0:0.7" />
  262. </Storyboard>
  263. </BeginStoryboard>
  264. </EventTrigger>
  265. </ControlTemplate.Triggers>
  266. </ControlTemplate>
  267. </Setter.Value>
  268. </Setter>
  269. </Style>
  270. </ResourceDictionary>