You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

199 lines
9.8 KiB

  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  2. <!--#region ScrollViewerStyle-->
  3. <ControlTemplate x:Key="MyScrollViewer" TargetType="{x:Type ScrollViewer}">
  4. <!-- View区域背景色 -->
  5. <Grid x:Name="Grid" Background="{TemplateBinding Background}">
  6. <Grid.ColumnDefinitions>
  7. <ColumnDefinition Width="*" />
  8. <ColumnDefinition Width="Auto" />
  9. </Grid.ColumnDefinitions>
  10. <Grid.RowDefinitions>
  11. <RowDefinition Height="*" />
  12. <RowDefinition Height="Auto" />
  13. </Grid.RowDefinitions>
  14. <Rectangle
  15. x:Name="Corner"
  16. Grid.Row="1"
  17. Grid.Column="1"
  18. Fill="White" />
  19. <ScrollContentPresenter
  20. x:Name="PART_ScrollContentPresenter"
  21. Grid.Row="0"
  22. Grid.Column="0"
  23. Margin="{TemplateBinding Padding}"
  24. CanContentScroll="{TemplateBinding CanContentScroll}"
  25. CanHorizontallyScroll="False"
  26. CanVerticallyScroll="False"
  27. Content="{TemplateBinding Content}"
  28. ContentTemplate="{TemplateBinding ContentTemplate}" />
  29. <ScrollBar
  30. x:Name="PART_VerticalScrollBar"
  31. Grid.Row="0"
  32. Grid.Column="1"
  33. AutomationProperties.AutomationId="VerticalScrollBar"
  34. Cursor="Arrow"
  35. Maximum="{TemplateBinding ScrollableHeight}"
  36. Minimum="0"
  37. Style="{DynamicResource MyScrollBarStyle}"
  38. ViewportSize="{TemplateBinding ViewportHeight}"
  39. Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
  40. Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
  41. <ScrollBar
  42. x:Name="PART_HorizontalScrollBar"
  43. Grid.Row="1"
  44. Grid.Column="0"
  45. AutomationProperties.AutomationId="HorizontalScrollBar"
  46. Cursor="Arrow"
  47. Maximum="{TemplateBinding ScrollableWidth}"
  48. Minimum="0"
  49. Orientation="Horizontal"
  50. Style="{DynamicResource MyScrollBarStyle}"
  51. ViewportSize="{TemplateBinding ViewportWidth}"
  52. Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
  53. Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
  54. </Grid>
  55. </ControlTemplate>
  56. <SolidColorBrush x:Key="ScrollBarDisabledBackground" Color="#F4F4F4" />
  57. <Style x:Key="VerticalScrollBarPageButton" TargetType="{x:Type RepeatButton}">
  58. <Setter Property="OverridesDefaultStyle" Value="true" />
  59. <Setter Property="Background" Value="Transparent" />
  60. <Setter Property="Focusable" Value="false" />
  61. <Setter Property="IsTabStop" Value="false" />
  62. <Setter Property="Template">
  63. <Setter.Value>
  64. <ControlTemplate TargetType="{x:Type RepeatButton}">
  65. <Rectangle
  66. Width="{TemplateBinding Width}"
  67. Height="{TemplateBinding Height}"
  68. Fill="{TemplateBinding Background}" />
  69. </ControlTemplate>
  70. </Setter.Value>
  71. </Setter>
  72. </Style>
  73. <!-- 滚动条颜色、圆角等设置 -->
  74. <Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
  75. <Setter Property="OverridesDefaultStyle" Value="true" />
  76. <Setter Property="IsTabStop" Value="false" />
  77. <Setter Property="Template">
  78. <Setter.Value>
  79. <ControlTemplate TargetType="{x:Type Thumb}">
  80. <!-- 滚动条颜色和圆角设置 -->
  81. <Rectangle
  82. Name="thumbRect"
  83. Fill="#03ffea"
  84. RadiusX="3"
  85. RadiusY="3" />
  86. <!-- 鼠标拉动滚动条时的颜色 -->
  87. <ControlTemplate.Triggers>
  88. <Trigger Property="IsMouseOver" Value="True">
  89. <Setter TargetName="thumbRect" Property="Fill" Value="CornflowerBlue" />
  90. </Trigger>
  91. </ControlTemplate.Triggers>
  92. </ControlTemplate>
  93. </Setter.Value>
  94. </Setter>
  95. </Style>
  96. <Style x:Key="HorizontalScrollBarPageButton" TargetType="{x:Type RepeatButton}">
  97. <Setter Property="OverridesDefaultStyle" Value="true" />
  98. <Setter Property="Background" Value="Transparent" />
  99. <Setter Property="Focusable" Value="false" />
  100. <Setter Property="IsTabStop" Value="false" />
  101. <Setter Property="Template">
  102. <Setter.Value>
  103. <ControlTemplate TargetType="{x:Type RepeatButton}">
  104. <Rectangle
  105. Width="{TemplateBinding Width}"
  106. Height="{TemplateBinding Height}"
  107. Fill="{TemplateBinding Background}" />
  108. </ControlTemplate>
  109. </Setter.Value>
  110. </Setter>
  111. </Style>
  112. <Style x:Key="MyScrollBarStyle" TargetType="{x:Type ScrollBar}">
  113. <Setter Property="Background" Value="AliceBlue" />
  114. <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />
  115. <Setter Property="Stylus.IsFlicksEnabled" Value="false" />
  116. <!-- 滚动条宽度 -->
  117. <Setter Property="Width" Value="8" />
  118. <Setter Property="MinWidth" Value="6" />
  119. <Setter Property="Template">
  120. <Setter.Value>
  121. <ControlTemplate TargetType="{x:Type ScrollBar}">
  122. <!-- 滚动条背景色 -->
  123. <Grid
  124. x:Name="Bg"
  125. Width="8"
  126. Background="#001f55"
  127. SnapsToDevicePixels="true">
  128. <Grid.RowDefinitions>
  129. <RowDefinition />
  130. </Grid.RowDefinitions>
  131. <Track
  132. x:Name="PART_Track"
  133. IsDirectionReversed="true"
  134. IsEnabled="{TemplateBinding IsMouseOver}">
  135. <Track.DecreaseRepeatButton>
  136. <RepeatButton Command="{x:Static ScrollBar.PageUpCommand}" Style="{StaticResource VerticalScrollBarPageButton}" />
  137. </Track.DecreaseRepeatButton>
  138. <Track.IncreaseRepeatButton>
  139. <RepeatButton Command="{x:Static ScrollBar.PageDownCommand}" Style="{StaticResource VerticalScrollBarPageButton}" />
  140. </Track.IncreaseRepeatButton>
  141. <Track.Thumb>
  142. <Thumb Style="{StaticResource ScrollBarThumb}" />
  143. </Track.Thumb>
  144. </Track>
  145. </Grid>
  146. <ControlTemplate.Triggers>
  147. <Trigger Property="IsEnabled" Value="false">
  148. <Setter TargetName="Bg" Property="Background" Value="{StaticResource ScrollBarDisabledBackground}" />
  149. </Trigger>
  150. </ControlTemplate.Triggers>
  151. </ControlTemplate>
  152. </Setter.Value>
  153. </Setter>
  154. <Style.Triggers>
  155. <Trigger Property="Orientation" Value="Horizontal">
  156. <Setter Property="Width" Value="Auto" />
  157. <Setter Property="MinWidth" Value="0" />
  158. <Setter Property="Height" Value="6" />
  159. <Setter Property="MinHeight" Value="6" />
  160. <Setter Property="Background" Value="AliceBlue" />
  161. <Setter Property="Template">
  162. <Setter.Value>
  163. <ControlTemplate TargetType="{x:Type ScrollBar}">
  164. <Grid
  165. x:Name="Bg"
  166. Background="Red"
  167. SnapsToDevicePixels="true">
  168. <Grid.ColumnDefinitions>
  169. <ColumnDefinition />
  170. </Grid.ColumnDefinitions>
  171. <Track x:Name="PART_Track" IsEnabled="{TemplateBinding IsMouseOver}">
  172. <Track.DecreaseRepeatButton>
  173. <RepeatButton Command="{x:Static ScrollBar.PageLeftCommand}" Style="{StaticResource HorizontalScrollBarPageButton}" />
  174. </Track.DecreaseRepeatButton>
  175. <Track.IncreaseRepeatButton>
  176. <RepeatButton Command="{x:Static ScrollBar.PageRightCommand}" Style="{StaticResource HorizontalScrollBarPageButton}" />
  177. </Track.IncreaseRepeatButton>
  178. <Track.Thumb>
  179. <Thumb Style="{StaticResource ScrollBarThumb}" />
  180. </Track.Thumb>
  181. </Track>
  182. </Grid>
  183. <ControlTemplate.Triggers>
  184. <Trigger Property="IsEnabled" Value="false">
  185. <Setter TargetName="Bg" Property="Background" Value="{StaticResource ScrollBarDisabledBackground}" />
  186. </Trigger>
  187. </ControlTemplate.Triggers>
  188. </ControlTemplate>
  189. </Setter.Value>
  190. </Setter>
  191. </Trigger>
  192. </Style.Triggers>
  193. </Style>
  194. <!--#endregion-->
  195. </ResourceDictionary>