ToggleButton.xaml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:ctrl="http://OpenSEMI.Ctrlib.com/presentation"
  7. mc:Ignorable="d">
  8. <LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0">
  9. <GradientStop Color="#FFFFFFFF" Offset="0"/>
  10. <GradientStop Color="#FFF0F0EA" Offset="0.9"/>
  11. </LinearGradientBrush>
  12. <SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/>
  13. <Style x:Key="ToggleButtonStyle1" TargetType="{x:Type ToggleButton}">
  14. <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
  15. <Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/>
  16. <Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/>
  17. <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
  18. <Setter Property="HorizontalContentAlignment" Value="Center"/>
  19. <Setter Property="VerticalContentAlignment" Value="Center"/>
  20. <Setter Property="Template">
  21. <Setter.Value>
  22. <ControlTemplate TargetType="{x:Type ToggleButton}">
  23. <ControlTemplate.Resources>
  24. <Storyboard x:Key="OnChecked1">
  25. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path">
  26. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="60,0,0,0"/>
  27. </ThicknessAnimationUsingKeyFrames>
  28. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path1">
  29. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="60,0,0,0"/>
  30. </ThicknessAnimationUsingKeyFrames>
  31. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path2">
  32. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="60,0,0,0"/>
  33. </ThicknessAnimationUsingKeyFrames>
  34. <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="displayText">
  35. <DiscreteStringKeyFrame KeyTime="0" Value="EN"/>
  36. </StringAnimationUsingKeyFrames>
  37. </Storyboard>
  38. <Storyboard x:Key="OnUnchecked1">
  39. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path">
  40. <EasingThicknessKeyFrame KeyTime="0" Value="60,0,0,0"/>
  41. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0"/>
  42. </ThicknessAnimationUsingKeyFrames>
  43. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path1">
  44. <EasingThicknessKeyFrame KeyTime="0" Value="60,0,0,0"/>
  45. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0"/>
  46. </ThicknessAnimationUsingKeyFrames>
  47. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path2">
  48. <EasingThicknessKeyFrame KeyTime="0" Value="60,0,0,0"/>
  49. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0"/>
  50. </ThicknessAnimationUsingKeyFrames>
  51. <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="displayText">
  52. <DiscreteStringKeyFrame KeyTime="0" Value="CHS"/>
  53. </StringAnimationUsingKeyFrames>
  54. </Storyboard>
  55. </ControlTemplate.Resources>
  56. <Border CornerRadius="20" Background="#FF3B3939" Width="100" Height="40">
  57. <Grid>
  58. <TextBlock x:Name="displayText" Text="CHS" Foreground="White" FontSize="20" VerticalAlignment="Center">
  59. <TextBlock.Style>
  60. <Style TargetType="TextBlock">
  61. <Style.Triggers>
  62. <Trigger Property="Text" Value="CHS">
  63. <Setter Property="HorizontalAlignment" Value="Right"/>
  64. <Setter Property="Padding" Value="0,0,15,0"/>
  65. </Trigger>
  66. <Trigger Property="Text" Value="EN">
  67. <Setter Property="HorizontalAlignment" Value="Left"/>
  68. <Setter Property="Padding" Value="15,0,0,0"/>
  69. </Trigger>
  70. </Style.Triggers>
  71. </Style>
  72. </TextBlock.Style>
  73. </TextBlock>
  74. <Path x:Name="path2" Fill="Black">
  75. <Path.Data>
  76. <GeometryGroup>
  77. <GeometryGroup.Children>
  78. <EllipseGeometry Center="20,20" RadiusX="17" RadiusY="17"></EllipseGeometry>
  79. </GeometryGroup.Children>
  80. </GeometryGroup>
  81. </Path.Data>
  82. </Path>
  83. <Path x:Name="path1" Fill="#FF818080">
  84. <Path.Data>
  85. <GeometryGroup>
  86. <GeometryGroup.Children>
  87. <EllipseGeometry Center="20,20" RadiusX="17" RadiusY="17"></EllipseGeometry>
  88. </GeometryGroup.Children>
  89. </GeometryGroup>
  90. </Path.Data>
  91. </Path>
  92. <Path x:Name="path">
  93. <Path.Fill>
  94. <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  95. <GradientStop Color="#FF807F7F" Offset="0"/>
  96. <GradientStop Color="#FF373636" Offset="1"/>
  97. </LinearGradientBrush>
  98. </Path.Fill>
  99. <Path.Data>
  100. <GeometryGroup>
  101. <GeometryGroup.Children>
  102. <EllipseGeometry Center="20,20" RadiusX="17" RadiusY="17"></EllipseGeometry>
  103. </GeometryGroup.Children>
  104. </GeometryGroup>
  105. </Path.Data>
  106. </Path>
  107. </Grid>
  108. </Border>
  109. <ControlTemplate.Triggers>
  110. <EventTrigger RoutedEvent="ToggleButton.Checked">
  111. <BeginStoryboard Storyboard="{StaticResource OnChecked1}"/>
  112. </EventTrigger>
  113. <EventTrigger RoutedEvent="ToggleButton.Unchecked">
  114. <BeginStoryboard x:Name="OnUnchecked1_BeginStoryboard" Storyboard="{StaticResource OnUnchecked1}"/>
  115. </EventTrigger>
  116. </ControlTemplate.Triggers>
  117. </ControlTemplate>
  118. </Setter.Value>
  119. </Setter>
  120. </Style>
  121. </ResourceDictionary>