ToggleSwitchStyles.xaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:Borders="clr-namespace:ToggleSwitch.Borders;assembly=ToggleSwitch"
  5. xmlns:ToggleSwitch="clr-namespace:ToggleSwitch;assembly=ToggleSwitch"
  6. xmlns:Utils="clr-namespace:ToggleSwitch.Utils;assembly=ToggleSwitch"
  7. xmlns:Controls="clr-namespace:ClashDotNetFramework.Models.Controls"
  8. xmlns:Converters="clr-namespace:ClashDotNetFramework.Models.Converters">
  9. <ResourceDictionary.MergedDictionaries>
  10. <ResourceDictionary Source="/ToggleSwitch;component/Themes/Generic.xaml"/>
  11. </ResourceDictionary.MergedDictionaries>
  12. <Converters:CornerRadiusValueConverter x:Key="CornerRadiusValueConverter"/>
  13. <Converters:ScalarValueConverter x:Key="ScalarConverter"/>
  14. <ControlTemplate x:Key="EngravedContentTemplate" TargetType="ContentControl">
  15. <Controls:DropShadowTextBlock
  16. DropShadowColor="#FFF7F7F7"
  17. DropShadowOpacity="0.3"
  18. DropShadowDistance="1"
  19. DropShadowAngle="90"
  20. Cursor="{TemplateBinding Cursor}"
  21. Text="{TemplateBinding Content}"
  22. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  23. Margin="{TemplateBinding Padding}"
  24. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  25. Foreground="{TemplateBinding Foreground}"
  26. FontFamily="{TemplateBinding FontFamily}"
  27. FontSize="{TemplateBinding FontSize}"
  28. FontWeight="{TemplateBinding FontWeight}"
  29. FontStyle="{TemplateBinding FontStyle}"
  30. HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
  31. VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Focusable="False" IsTabStop="False"/>
  32. </ControlTemplate>
  33. <ControlTemplate x:Key="iOS5ThumbTemplate" TargetType="Thumb">
  34. <Grid Background="Transparent">
  35. <VisualStateManager.VisualStateGroups>
  36. <VisualStateGroup x:Name="CommonStates">
  37. <VisualState x:Name="Normal"/>
  38. <VisualState x:Name="MouseOver">
  39. <Storyboard>
  40. <DoubleAnimation Duration="0" To="0.05" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/>
  41. </Storyboard>
  42. </VisualState>
  43. <VisualState x:Name="Pressed">
  44. <Storyboard>
  45. <DoubleAnimation Duration="0" To="0.25" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/>
  46. </Storyboard>
  47. </VisualState>
  48. <VisualState x:Name="Disabled">
  49. <Storyboard>
  50. <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="DisabledVisualElement"/>
  51. </Storyboard>
  52. </VisualState>
  53. </VisualStateGroup>
  54. <VisualStateGroup x:Name="FocusStates">
  55. <VisualState x:Name="Focused">
  56. <Storyboard>
  57. <DoubleAnimation Duration="0" To="0.05" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/>
  58. </Storyboard>
  59. </VisualState>
  60. <VisualState x:Name="Unfocused"/>
  61. </VisualStateGroup>
  62. <VisualStateGroup x:Name="CheckStates">
  63. <VisualState x:Name="Unchecked"/>
  64. <VisualState x:Name="Checked"/>
  65. </VisualStateGroup>
  66. </VisualStateManager.VisualStateGroups>
  67. <Borders:OuterGlowBorder OuterGlowSize="1" BorderThickness="0" OuterGlowColor="Black" Background="Transparent" CornerRadius="10" ShadowCornerRadius="12" IsTabStop="False" OuterGlowOpacity="0.05" >
  68. <Grid>
  69. <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="11" Background="{TemplateBinding Background}">
  70. <Borders:ClippingBorder x:Name="Background" CornerRadius="12" IsTabStop="False" Background="{TemplateBinding Background}" BorderBrush="#FFEBEBEB" BorderThickness="1"/>
  71. </Border>
  72. <Borders:ClippingBorder x:Name="BackgroundAnimation" Background="Black" Opacity="0" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="Black" CornerRadius="11" IsTabStop="False"/>
  73. <Rectangle x:Name="DisabledVisualElement" Fill="White" IsHitTestVisible="false" Opacity="0" RadiusY="11" RadiusX="11"/>
  74. <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="9" RadiusX="9" StrokeThickness="1"/>
  75. </Grid>
  76. </Borders:OuterGlowBorder>
  77. </Grid>
  78. </ControlTemplate>
  79. <ControlTemplate x:Key="BrushedThumbTemplate" TargetType="Thumb">
  80. <Grid Background="Transparent">
  81. <VisualStateManager.VisualStateGroups>
  82. <VisualStateGroup x:Name="CommonStates">
  83. <VisualState x:Name="Normal"/>
  84. <VisualState x:Name="MouseOver">
  85. <Storyboard>
  86. <DoubleAnimation Duration="0" To="0.05" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/>
  87. </Storyboard>
  88. </VisualState>
  89. <VisualState x:Name="Pressed">
  90. <Storyboard>
  91. <DoubleAnimation Duration="0" To="0.25" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/>
  92. </Storyboard>
  93. </VisualState>
  94. <VisualState x:Name="Disabled">
  95. <Storyboard>
  96. <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="DisabledVisualElement"/>
  97. </Storyboard>
  98. </VisualState>
  99. </VisualStateGroup>
  100. <VisualStateGroup x:Name="FocusStates">
  101. <VisualState x:Name="Focused">
  102. <Storyboard>
  103. <DoubleAnimation Duration="0" To="0.05" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/>
  104. </Storyboard>
  105. </VisualState>
  106. <VisualState x:Name="Unfocused"/>
  107. </VisualStateGroup>
  108. </VisualStateManager.VisualStateGroups>
  109. <Image Source="/Demo;component/Images/Knob.png"/>
  110. <Borders:ClippingBorder x:Name="BackgroundAnimation" Background="Black" Opacity="0" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="Black" CornerRadius="14"/>
  111. <Rectangle x:Name="DisabledVisualElement" IsHitTestVisible="false" Opacity="0" RadiusY="14" RadiusX="14"/>
  112. <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Opacity="0" RadiusY="14" RadiusX="14"/>
  113. </Grid>
  114. </ControlTemplate>
  115. <Style x:Key="iOS5ToggleSwitchStyle" TargetType="ToggleSwitch:HorizontalToggleSwitch">
  116. <Setter Property="Foreground" Value="White"/>
  117. <Setter Property="Width" Value="50"/>
  118. <Setter Property="Height" Value="24"/>
  119. <Setter Property="BorderBrush" Value="#AFBEBEBE"/>
  120. <Setter Property="BorderThickness" Value="1"/>
  121. <Setter Property="Padding" Value="0,4"/>
  122. <Setter Property="UncheckedForeground" Value="#FF5F5F5F"/>
  123. <Setter Property="CheckedForeground" Value="White" />
  124. <Setter Property="ThumbSize" Value="24"/>
  125. <Setter Property="FontWeight" Value="SemiBold"/>
  126. <Setter Property="FontFamily" Value="Arial"/>
  127. <Setter Property="FontSize" Value="12"/>
  128. <Setter Property="ContentTemplate" Value="{StaticResource EngravedContentTemplate}" />
  129. <Setter Property="HorizontalContentAlignment" Value="Center" />
  130. <Setter Property="VerticalContentAlignment" Value="Center" />
  131. <Setter Property="ThumbTemplate" Value="{StaticResource iOS5ThumbTemplate}"/>
  132. <Setter Property="ThumbBrush" Value="White" />
  133. <Setter Property="CheckedBackground" Value="{DynamicResource ToggleSwitchCheckedBackground}"/>
  134. <Setter Property="UncheckedBackground" Value="{DynamicResource ToggleSwitchUnCheckedBackground}"/>
  135. <Setter Property="Template">
  136. <Setter.Value>
  137. <ControlTemplate TargetType="ToggleSwitch:HorizontalToggleSwitch">
  138. <Grid>
  139. <VisualStateManager.VisualStateGroups>
  140. <VisualStateGroup x:Name="CommonStates">
  141. <VisualState x:Name="Normal"/>
  142. <VisualState x:Name="Disabled">
  143. <Storyboard>
  144. <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="DisabledOverlay">
  145. <DiscreteObjectKeyFrame KeyTime="0">
  146. <DiscreteObjectKeyFrame.Value>
  147. <Visibility>Visible</Visibility>
  148. </DiscreteObjectKeyFrame.Value>
  149. </DiscreteObjectKeyFrame>
  150. </ObjectAnimationUsingKeyFrames>
  151. </Storyboard>
  152. </VisualState>
  153. <VisualState x:Name="MouseOver"/>
  154. <VisualState x:Name="Pressed"/>
  155. </VisualStateGroup>
  156. <VisualStateGroup x:Name="CheckStates">
  157. <VisualStateGroup.Transitions>
  158. <VisualTransition GeneratedDuration="0:0:0.10" To="Unchecked"/>
  159. <VisualTransition GeneratedDuration="0:0:0.10" To="Checked"/>
  160. </VisualStateGroup.Transitions>
  161. <VisualState x:Name="Checked"/>
  162. <VisualState x:Name="Unchecked"/>
  163. <VisualState x:Name="DraggingChecked"/>
  164. <VisualState x:Name="DraggingUnchecked"/>
  165. </VisualStateGroup>
  166. </VisualStateManager.VisualStateGroups>
  167. <Borders:ClippingBorder x:Name="SwitchRoot" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="{Binding ActualHeightValue, ConverterParameter=0.5, Converter={StaticResource CornerRadiusValueConverter}, ElementName=ActualSizeProxy}" IsTabStop="False" BorderThickness="1" >
  168. <Canvas MinWidth="{TemplateBinding ThumbSize}" MinHeight="{TemplateBinding FontSize}">
  169. <Utils:ActualSizePropertyProxy x:Name="ActualSizeProxy" Element="{Binding Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" Visibility="Collapsed" IsHitTestVisible="False"/>
  170. <Grid x:Name="SwitchTrack" Cursor="Hand" Margin="0,-1,0,0" Height="{Binding ActualHeightValue, ElementName=ActualSizeProxy, Mode=OneWay}" >
  171. <StackPanel Orientation="Horizontal">
  172. <Border Background="{TemplateBinding CheckedBackground}" Margin="-1,0,0,0" Padding="1,0,0,0">
  173. <ContentControl x:Name="SwitchChecked"
  174. Content="{TemplateBinding CheckedContent}"
  175. HorizontalContentAlignment="Center"
  176. VerticalContentAlignment="Center"
  177. Margin="{TemplateBinding Padding}"
  178. Template="{TemplateBinding ContentTemplate}"
  179. Foreground="{TemplateBinding CheckedForeground}"
  180. IsTabStop="False"
  181. FontSize="{TemplateBinding FontSize}"
  182. FontFamily="{TemplateBinding FontFamily}"
  183. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  184. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  185. </Border>
  186. <Border Background="{TemplateBinding UncheckedBackground}" Margin="-1,0,0,0">
  187. <ContentControl x:Name="SwitchUnchecked"
  188. Content="{TemplateBinding UncheckedContent}"
  189. HorizontalContentAlignment="Center"
  190. VerticalContentAlignment="Center"
  191. Margin="{TemplateBinding Padding}"
  192. Template="{TemplateBinding ContentTemplate}"
  193. Foreground="{TemplateBinding UncheckedForeground}"
  194. IsTabStop="False"
  195. FontSize="{TemplateBinding FontSize}"
  196. FontFamily="{TemplateBinding FontFamily}"
  197. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  198. VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
  199. </Border>
  200. </StackPanel>
  201. </Grid>
  202. <Thumb x:Name="SwitchThumb"
  203. Background="{TemplateBinding ThumbBrush}"
  204. Template="{TemplateBinding ThumbTemplate}"
  205. Cursor="Hand"
  206. Height="{Binding ActualHeightValue, ElementName=ActualSizeProxy, Mode=OneWay}"
  207. Width="{TemplateBinding ThumbSize}"
  208. IsTabStop="False"
  209. BorderBrush="{TemplateBinding BorderBrush}" Margin="46,-1,0,0" Focusable="False"/>
  210. </Canvas>
  211. </Borders:ClippingBorder>
  212. <Border x:Name="DisabledOverlay" Background="#AAEEEEEE" Visibility="Collapsed" CornerRadius="{Binding ActualHeightValue, ConverterParameter=0.5, Converter={StaticResource CornerRadiusValueConverter}, ElementName=ActualSizeProxy}"/>
  213. </Grid>
  214. </ControlTemplate>
  215. </Setter.Value>
  216. </Setter>
  217. </Style>
  218. </ResourceDictionary>