Generic.xaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:Converters="clr-namespace:CustomUI.Converters"
  5. xmlns:UI="clr-namespace:CustomUI"
  6. xmlns:ec="http://schemas.microsoft.com/expression/2010/controls"
  7. xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing">
  8. <Converters:WordAngleConverter x:Key="WordAngleConverter" />
  9. <!-- 单独提出作为资源引用,并且加上x:Shared="False"是为了防止出现“指定的元素已经是另一个元素的逻辑子元素。请先将其断开连接” -->
  10. <DataTemplate x:Key="DefaultLabelPanel" x:Shared="False">
  11. <Border
  12. Width="70"
  13. Margin="0,0,0,20"
  14. Padding="0,2"
  15. HorizontalAlignment="Center"
  16. VerticalAlignment="Bottom"
  17. BorderBrush="#FFFFCA02"
  18. BorderThickness="1"
  19. CornerRadius="3"
  20. SnapsToDevicePixels="True"
  21. UseLayoutRounding="True">
  22. <TextBlock
  23. HorizontalAlignment="Center"
  24. VerticalAlignment="Center"
  25. FontFamily="Agency FB"
  26. Foreground="White"
  27. Text="{Binding Path=Value, StringFormat={}{0:N1}°C, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UI:Dashboard}}}" />
  28. </Border>
  29. </DataTemplate>
  30. <!-- 速度盘 -->
  31. <ControlTemplate x:Key="Speed" TargetType="{x:Type UI:Dashboard}">
  32. <Grid>
  33. <!-- 背景圆盘 -->
  34. <Ellipse Fill="#6452A4" />
  35. <Grid Margin="20">
  36. <!-- 刻度盘当前值对应的圆弧 -->
  37. <ed:Arc
  38. x:Name="PART_IncreaseCircle"
  39. ArcThickness="8"
  40. ArcThicknessUnit="Pixel"
  41. Fill="#BB0104"
  42. RenderTransformOrigin="0.5,0.5"
  43. StartAngle="{TemplateBinding StartAngle}"
  44. Stretch="None" />
  45. <!-- 刻度盘完整圆弧 -->
  46. <ed:Arc
  47. x:Name="DoubleCircle"
  48. ArcThickness="8"
  49. ArcThicknessUnit="Pixel"
  50. EndAngle="{TemplateBinding EndAngle}"
  51. StartAngle="{TemplateBinding StartAngle}"
  52. Stretch="None"
  53. Stroke="#FFFFCA02"
  54. StrokeThickness="1" />
  55. <!-- 短刻度 -->
  56. <ec:PathListBox
  57. x:Name="ShoartTick"
  58. IsHitTestVisible="False"
  59. ItemsSource="{TemplateBinding ShortTicks}">
  60. <ec:PathListBox.ItemTemplate>
  61. <DataTemplate>
  62. <Border
  63. Width="1"
  64. Height="8"
  65. Background="White"
  66. SnapsToDevicePixels="True"
  67. UseLayoutRounding="True" />
  68. </DataTemplate>
  69. </ec:PathListBox.ItemTemplate>
  70. <ec:PathListBox.LayoutPaths>
  71. <ec:LayoutPath
  72. Distribution="Even"
  73. Orientation="OrientToPath"
  74. SourceElement="{Binding ElementName=ShortTickPath}" />
  75. </ec:PathListBox.LayoutPaths>
  76. </ec:PathListBox>
  77. <!-- 长刻度 -->
  78. <ec:PathListBox
  79. x:Name="LongTick"
  80. IsHitTestVisible="False"
  81. ItemsSource="{TemplateBinding LongTicks}">
  82. <ec:PathListBox.ItemTemplate>
  83. <DataTemplate>
  84. <Border
  85. Width="1"
  86. Height="13"
  87. Background="White"
  88. SnapsToDevicePixels="True"
  89. UseLayoutRounding="True" />
  90. </DataTemplate>
  91. </ec:PathListBox.ItemTemplate>
  92. <ec:PathListBox.LayoutPaths>
  93. <ec:LayoutPath
  94. Distribution="Even"
  95. Orientation="OrientToPath"
  96. SourceElement="{Binding ElementName=LongTickPath}" />
  97. </ec:PathListBox.LayoutPaths>
  98. </ec:PathListBox>
  99. <!-- 刻度上显示的数字 -->
  100. <ec:PathListBox
  101. x:Name="Number"
  102. IsHitTestVisible="False"
  103. ItemsSource="{TemplateBinding NumberList}">
  104. <ec:PathListBox.ItemTemplate>
  105. <DataTemplate>
  106. <TextBlock Text="{Binding}" />
  107. </DataTemplate>
  108. </ec:PathListBox.ItemTemplate>
  109. <ec:PathListBox.LayoutPaths>
  110. <ec:LayoutPath
  111. Distribution="Even"
  112. Orientation="OrientToPath"
  113. SourceElement="{Binding ElementName=NumberPath}" />
  114. </ec:PathListBox.LayoutPaths>
  115. </ec:PathListBox>
  116. <ed:Arc
  117. x:Name="LongTickPath"
  118. Margin="0"
  119. ArcThickness="0"
  120. ArcThicknessUnit="Pixel"
  121. EndAngle="{TemplateBinding EndAngle}"
  122. StartAngle="{TemplateBinding StartAngle}"
  123. Stretch="None" />
  124. <ed:Arc
  125. x:Name="ShortTickPath"
  126. Margin="5"
  127. ArcThickness="0"
  128. ArcThicknessUnit="Pixel"
  129. EndAngle="{TemplateBinding EndAngle}"
  130. StartAngle="{TemplateBinding StartAngle}"
  131. Stretch="None" />
  132. <ed:Arc
  133. x:Name="NumberPath"
  134. Margin="20"
  135. ArcThickness="0"
  136. ArcThicknessUnit="Pixel"
  137. EndAngle="{TemplateBinding EndAngle}"
  138. StartAngle="{TemplateBinding StartAngle}"
  139. Stretch="None" />
  140. <!--#region 表盘指针-->
  141. <Ellipse
  142. Width="15"
  143. Height="15"
  144. Stroke="Black">
  145. <Ellipse.Fill>
  146. <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
  147. <GradientStop Offset="0" Color="#FF2C2C2C" />
  148. <GradientStop Offset="0.997" Color="Black" />
  149. </LinearGradientBrush>
  150. </Ellipse.Fill>
  151. </Ellipse>
  152. <Ellipse
  153. Width="10"
  154. Height="10"
  155. Stroke="#FFFFCA02" />
  156. <ed:RegularPolygon
  157. x:Name="Finger"
  158. Width="4"
  159. Height="50"
  160. Fill="#FFFFCA02"
  161. PointCount="3"
  162. RenderTransformOrigin="0.5,1.118"
  163. Stretch="Fill">
  164. <ed:RegularPolygon.RenderTransform>
  165. <TransformGroup>
  166. <ScaleTransform />
  167. <SkewTransform />
  168. <RotateTransform Angle="{Binding EndAngle, ElementName=PART_IncreaseCircle}" />
  169. <TranslateTransform Y="-31" />
  170. </TransformGroup>
  171. </ed:RegularPolygon.RenderTransform>
  172. </ed:RegularPolygon>
  173. <!--#endregion-->
  174. </Grid>
  175. <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
  176. </Grid>
  177. </ControlTemplate>
  178. <!-- 流量盘 -->
  179. <ControlTemplate x:Key="Flow" TargetType="{x:Type UI:Dashboard}">
  180. <Grid>
  181. <!-- 刻度盘完整圆弧 -->
  182. <ed:Arc
  183. x:Name="DoubleCircle"
  184. Margin="50"
  185. ArcThickness="1"
  186. ArcThicknessUnit="Pixel"
  187. EndAngle="{TemplateBinding EndAngle}"
  188. SnapsToDevicePixels="True"
  189. StartAngle="{TemplateBinding StartAngle}"
  190. Stretch="None"
  191. Stroke="#746E7A"
  192. StrokeThickness="1"
  193. UseLayoutRounding="True" />
  194. <!-- 刻度盘当前值对应的圆弧 -->
  195. <ed:Arc
  196. x:Name="PART_IncreaseCircle"
  197. Margin="50"
  198. ArcThickness="1"
  199. ArcThicknessUnit="Pixel"
  200. RenderTransformOrigin="0.5,0.5"
  201. StartAngle="{TemplateBinding StartAngle}"
  202. Stretch="None"
  203. Stroke="Red"
  204. StrokeThickness="1" />
  205. <!-- 短刻度 -->
  206. <ec:PathListBox
  207. x:Name="ShoartTick"
  208. IsHitTestVisible="False"
  209. ItemsSource="{TemplateBinding ShortTicks}">
  210. <ec:PathListBox.ItemTemplate>
  211. <DataTemplate>
  212. <Border
  213. Width="1"
  214. Height="8"
  215. Background="{Binding ShortTicksBrush, RelativeSource={RelativeSource AncestorType={x:Type UI:Dashboard}}}"
  216. SnapsToDevicePixels="True"
  217. UseLayoutRounding="False" />
  218. </DataTemplate>
  219. </ec:PathListBox.ItemTemplate>
  220. <ec:PathListBox.LayoutPaths>
  221. <ec:LayoutPath
  222. Distribution="Even"
  223. Orientation="OrientToPath"
  224. SourceElement="{Binding ElementName=ShortTickPath}" />
  225. </ec:PathListBox.LayoutPaths>
  226. </ec:PathListBox>
  227. <!-- 长刻度 -->
  228. <ec:PathListBox
  229. x:Name="LongTick"
  230. IsHitTestVisible="False"
  231. ItemsSource="{TemplateBinding LongTicks}">
  232. <ec:PathListBox.ItemTemplate>
  233. <DataTemplate>
  234. <Border
  235. Width="1"
  236. Height="13"
  237. Background="{Binding LongTicksBrush, RelativeSource={RelativeSource AncestorType={x:Type UI:Dashboard}}}"
  238. SnapsToDevicePixels="True"
  239. UseLayoutRounding="False" />
  240. </DataTemplate>
  241. </ec:PathListBox.ItemTemplate>
  242. <ec:PathListBox.LayoutPaths>
  243. <ec:LayoutPath
  244. Distribution="Even"
  245. Orientation="OrientToPath"
  246. SourceElement="{Binding ElementName=LongTickPath}" />
  247. </ec:PathListBox.LayoutPaths>
  248. </ec:PathListBox>
  249. <!-- 刻度上显示的数字 -->
  250. <ec:PathListBox
  251. x:Name="Number"
  252. IsHitTestVisible="False"
  253. ItemsSource="{TemplateBinding NumberList}">
  254. <ec:PathListBox.ItemTemplate>
  255. <DataTemplate>
  256. <TextBlock RenderTransformOrigin="0.5,0.5" Text="{Binding}">
  257. <!--<TextBlock.RenderTransform>
  258. <TransformGroup>
  259. <ScaleTransform />
  260. <SkewTransform />
  261. <RotateTransform Angle="{Binding}" />
  262. <TranslateTransform />
  263. </TransformGroup>
  264. </TextBlock.RenderTransform>-->
  265. </TextBlock>
  266. </DataTemplate>
  267. </ec:PathListBox.ItemTemplate>
  268. <ec:PathListBox.LayoutPaths>
  269. <ec:LayoutPath
  270. Distribution="Even"
  271. Orientation="OrientToPath"
  272. SourceElement="{Binding ElementName=NumberPath}" />
  273. </ec:PathListBox.LayoutPaths>
  274. </ec:PathListBox>
  275. <!--#region 路径-->
  276. <ed:Arc
  277. x:Name="LongTickPath"
  278. Margin="0"
  279. ArcThickness="0"
  280. ArcThicknessUnit="Pixel"
  281. EndAngle="{TemplateBinding EndAngle}"
  282. StartAngle="{TemplateBinding StartAngle}"
  283. Stretch="None" />
  284. <ed:Arc
  285. x:Name="ShortTickPath"
  286. Margin="5"
  287. ArcThickness="0"
  288. ArcThicknessUnit="Pixel"
  289. EndAngle="{TemplateBinding EndAngle}"
  290. StartAngle="{TemplateBinding StartAngle}"
  291. Stretch="None" />
  292. <ed:Arc
  293. x:Name="NumberPath"
  294. Margin="20"
  295. ArcThickness="0"
  296. ArcThicknessUnit="Pixel"
  297. EndAngle="{TemplateBinding EndAngle}"
  298. StartAngle="{TemplateBinding StartAngle}"
  299. Stretch="None" />
  300. <!--#endregion-->
  301. <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
  302. </Grid>
  303. </ControlTemplate>
  304. <Style TargetType="{x:Type UI:Dashboard}">
  305. <Setter Property="StartAngle" Value="-130" />
  306. <Setter Property="EndAngle" Value="130" />
  307. <Setter Property="FontSize" Value="12" />
  308. <Setter Property="Foreground" Value="#FFFFFF" />
  309. <Setter Property="Template" Value="{StaticResource Speed}" />
  310. <Setter Property="ContentTemplate" Value="{StaticResource DefaultLabelPanel}" />
  311. <Style.Triggers>
  312. <Trigger Property="Skin" Value="Flow">
  313. <Setter Property="StartAngle" Value="-120" />
  314. <Setter Property="EndAngle" Value="120" />
  315. <Setter Property="Foreground" Value="#929093" />
  316. <Setter Property="BorderBrush" Value="#746E7A" />
  317. <Setter Property="ShortTicksBrush" Value="#746E7A" />
  318. <Setter Property="LongTicksBrush" Value="#746E7A" />
  319. <Setter Property="Template" Value="{StaticResource Flow}" />
  320. </Trigger>
  321. </Style.Triggers>
  322. </Style>
  323. </ResourceDictionary>