ToggleButton.xaml 8.3 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="Transparent"/>
  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="Cursor" Value="Hand"/>
  21. <Setter Property="Template">
  22. <Setter.Value>
  23. <ControlTemplate TargetType="{x:Type ToggleButton}">
  24. <ControlTemplate.Resources>
  25. <Storyboard x:Key="OnChecked1">
  26. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path">
  27. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="110,0,0,0"/>
  28. </ThicknessAnimationUsingKeyFrames>
  29. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path1">
  30. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="110,0,0,0"/>
  31. </ThicknessAnimationUsingKeyFrames>
  32. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path2">
  33. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="110,0,0,0"/>
  34. </ThicknessAnimationUsingKeyFrames>
  35. <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="displayText">
  36. <DiscreteStringKeyFrame KeyTime="0" Value="Enable"/>
  37. </StringAnimationUsingKeyFrames>
  38. </Storyboard>
  39. <Storyboard x:Key="OnUnchecked1">
  40. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path">
  41. <EasingThicknessKeyFrame KeyTime="0" Value="60,0,0,0"/>
  42. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0"/>
  43. </ThicknessAnimationUsingKeyFrames>
  44. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path1">
  45. <EasingThicknessKeyFrame KeyTime="0" Value="60,0,0,0"/>
  46. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0"/>
  47. </ThicknessAnimationUsingKeyFrames>
  48. <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path2">
  49. <EasingThicknessKeyFrame KeyTime="0" Value="60,0,0,0"/>
  50. <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0"/>
  51. </ThicknessAnimationUsingKeyFrames>
  52. <StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="displayText">
  53. <DiscreteStringKeyFrame KeyTime="0" Value="Disable"/>
  54. </StringAnimationUsingKeyFrames>
  55. </Storyboard>
  56. </ControlTemplate.Resources>
  57. <Border CornerRadius="20" Background="Green" Width="{TemplateBinding Width}" Height="40">
  58. <Grid>
  59. <TextBlock x:Name="displayText" Text="Disable" Foreground="Black" FontSize="20" VerticalAlignment="Center">
  60. <TextBlock.Style>
  61. <Style TargetType="TextBlock">
  62. <Style.Triggers>
  63. <Trigger Property="Text" Value="Disable">
  64. <Setter Property="HorizontalAlignment" Value="Right"/>
  65. <Setter Property="Padding" Value="0,0,15,0"/>
  66. </Trigger>
  67. <Trigger Property="Text" Value="EN">
  68. <Setter Property="HorizontalAlignment" Value="Left"/>
  69. <Setter Property="Padding" Value="15,0,0,0"/>
  70. </Trigger>
  71. </Style.Triggers>
  72. </Style>
  73. </TextBlock.Style>
  74. </TextBlock>
  75. <Path x:Name="path2" Fill="Transparent">
  76. <Path.Data>
  77. <GeometryGroup>
  78. <GeometryGroup.Children>
  79. <EllipseGeometry Center="20,20" RadiusX="17" RadiusY="17"></EllipseGeometry>
  80. </GeometryGroup.Children>
  81. </GeometryGroup>
  82. </Path.Data>
  83. </Path>
  84. <Path x:Name="path1" Fill="Transparent">
  85. <Path.Data>
  86. <GeometryGroup>
  87. <GeometryGroup.Children>
  88. <EllipseGeometry Center="20,20" RadiusX="17" RadiusY="17"></EllipseGeometry>
  89. </GeometryGroup.Children>
  90. </GeometryGroup>
  91. </Path.Data>
  92. </Path>
  93. <Path x:Name="path">
  94. <Path.Fill>
  95. <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  96. <GradientStop Color="#FF807F7F" Offset="0"/>
  97. <GradientStop Color="#FF373636" Offset="1"/>
  98. </LinearGradientBrush>
  99. </Path.Fill>
  100. <Path.Data>
  101. <GeometryGroup>
  102. <GeometryGroup.Children>
  103. <EllipseGeometry Center="20,20" RadiusX="17" RadiusY="17"></EllipseGeometry>
  104. </GeometryGroup.Children>
  105. </GeometryGroup>
  106. </Path.Data>
  107. </Path>
  108. </Grid>
  109. </Border>
  110. <ControlTemplate.Triggers>
  111. <EventTrigger RoutedEvent="ToggleButton.Checked">
  112. <BeginStoryboard Storyboard="{StaticResource OnChecked1}"/>
  113. </EventTrigger>
  114. <EventTrigger RoutedEvent="ToggleButton.Unchecked">
  115. <BeginStoryboard x:Name="OnUnchecked1_BeginStoryboard" Storyboard="{StaticResource OnUnchecked1}"/>
  116. </EventTrigger>
  117. </ControlTemplate.Triggers>
  118. </ControlTemplate>
  119. </Setter.Value>
  120. </Setter>
  121. </Style>
  122. </ResourceDictionary>