| 1 | <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| 2 | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| 3 | xmlns:local="clr-namespace:UI.Controls.Toggle"> |
| 4 | |
| 5 | <Style TargetType="{x:Type local:Toggle}"> |
| 6 | <Setter Property="Width" Value="auto"/> |
| 7 | <Setter Property="Height" Value="22"/> |
| 8 | <Setter Property="Cursor" Value="Hand"/> |
| 9 | <Setter Property="FocusVisualStyle" Value="{x:Null}"/> |
| 10 | <Setter Property="Background" Value="Transparent"/> |
| 11 | <Setter Property="Template"> |
| 12 | <Setter.Value> |
| 13 | <ControlTemplate TargetType="{x:Type local:Toggle}"> |
| 14 | <Border x:Name="Border" Background="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" CornerRadius="4" Margin="{TemplateBinding Margin}"> |
| 15 | <Grid> |
| 16 | <Grid.ColumnDefinitions> |
| 17 | <ColumnDefinition Width="auto"/> |
| 18 | <ColumnDefinition Width="50"/> |
| 19 | <ColumnDefinition Width="auto"/> |
| 20 | </Grid.ColumnDefinitions> |
| 21 | <Border x:Name="Button" Grid.Column="1" Background="#f5f5f5" CornerRadius="10" Padding="5"> |
| 22 | <Border x:Name="Mark" Width="12" Height="12" CornerRadius="15" Background="#5d5d5d" VerticalAlignment="Center" HorizontalAlignment="Left"> |
| 23 | <Border.RenderTransform> |
| 24 | <TranslateTransform X="0"/> |
| 25 | </Border.RenderTransform> |
| 26 | </Border> |
| 27 | </Border> |
| 28 | <Grid x:Name="TextContainer" Grid.Column="2" Margin="10,0,0,0"> |
| 29 | <TextBlock x:Name="OnText" VerticalAlignment="Center" Text="{TemplateBinding OnText}"/> |
| 30 | <TextBlock x:Name="OffText" VerticalAlignment="Center" Text="{TemplateBinding OffText}"/> |
| 31 | </Grid> |
| 32 | |
| 33 | |
| 34 | </Grid> |
| 35 | |
| 36 | <VisualStateManager.VisualStateGroups> |
| 37 | <VisualStateGroup x:Name="CommonStates"> |
| 38 | <VisualState x:Name="On"> |
| 39 | <Storyboard> |
| 40 | <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.RenderTransform). |
| 41 | (TranslateTransform.X)" |
| 42 | Storyboard.TargetName="Mark"> |
| 43 | <EasingDoubleKeyFrame KeyTime="00:00:0" |
| 44 | Value="0" /> |
| 45 | <EasingDoubleKeyFrame KeyTime="00:00:0.2" |
| 46 | Value="28" /> |
| 47 | </DoubleAnimationUsingKeyFrames> |
| 48 | |
| 49 | <ColorAnimationUsingKeyFrames |
| 50 | Storyboard.TargetName="Mark" |
| 51 | Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"> |
| 52 | <EasingColorKeyFrame KeyTime="00:00:0.2" |
| 53 | Value="White"/> |
| 54 | </ColorAnimationUsingKeyFrames> |
| 55 | |
| 56 | <ColorAnimationUsingKeyFrames |
| 57 | Storyboard.TargetName="Button" |
| 58 | Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"> |
| 59 | <EasingColorKeyFrame KeyTime="00:00:0.2" |
| 60 | Value="{DynamicResource ThemeColor}"/> |
| 61 | </ColorAnimationUsingKeyFrames> |
| 62 | </Storyboard> |
| 63 | </VisualState> |
| 64 | <VisualState x:Name="Off"> |
| 65 | <Storyboard> |
| 66 | <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.RenderTransform). |
| 67 | (TranslateTransform.X)" |
| 68 | Storyboard.TargetName="Mark"> |
| 69 | <EasingDoubleKeyFrame KeyTime="00:00:0.2" |
| 70 | Value="0" /> |
| 71 | <EasingDoubleKeyFrame KeyTime="00:00:0" |
| 72 | Value="28" /> |
| 73 | </DoubleAnimationUsingKeyFrames> |
| 74 | </Storyboard> |
| 75 | </VisualState> |
| 76 | </VisualStateGroup> |
| 77 | </VisualStateManager.VisualStateGroups> |
| 78 | </Border> |
| 79 | <ControlTemplate.Triggers> |
| 80 | <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" Value="True"> |
| 81 | <Setter TargetName="Button" Property="Background" Value="{DynamicResource ThemeBrush}"/> |
| 82 | <Setter TargetName="Mark" Property="Background" Value="White"/> |
| 83 | <DataTrigger.EnterActions> |
| 84 | <BeginStoryboard> |
| 85 | <Storyboard> |
| 86 | <DoubleAnimation Storyboard.TargetProperty="(Border.RenderTransform). |
| 87 | (TranslateTransform.X)" |
| 88 | Storyboard.TargetName="Mark" To="28" Duration="0"></DoubleAnimation> |
| 89 | </Storyboard> |
| 90 | </BeginStoryboard> |
| 91 | </DataTrigger.EnterActions> |
| 92 | </DataTrigger> |
| 93 | <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" Value="False"> |
| 94 | <DataTrigger.EnterActions> |
| 95 | <BeginStoryboard> |
| 96 | <Storyboard> |
| 97 | <DoubleAnimation Storyboard.TargetProperty="(Border.RenderTransform). |
| 98 | (TranslateTransform.X)" |
| 99 | Storyboard.TargetName="Mark" To="0" Duration="0"></DoubleAnimation> |
| 100 | |
| 101 | </Storyboard> |
| 102 | </BeginStoryboard> |
| 103 | </DataTrigger.EnterActions> |
| 104 | </DataTrigger> |
| 105 | <Trigger Property="IsChecked" Value="True"> |
| 106 | <Setter TargetName="OffText" Property="Visibility" Value="Collapsed"/> |
| 107 | <Setter TargetName="OnText" Property="Visibility" Value="Visible"/> |
| 108 | </Trigger> |
| 109 | <Trigger Property="IsChecked" Value="False"> |
| 110 | <Setter TargetName="OffText" Property="Visibility" Value="Visible"/> |
| 111 | <Setter TargetName="OnText" Property="Visibility" Value="Collapsed"/> |
| 112 | </Trigger> |
| 113 | <Trigger Property="IsChecked" Value="False"> |
| 114 | <Setter TargetName="OffText" Property="Visibility" Value="Visible"/> |
| 115 | <Setter TargetName="OnText" Property="Visibility" Value="Collapsed"/> |
| 116 | </Trigger> |
| 117 | <Trigger Property="TextPosition" Value="Left"> |
| 118 | <Setter TargetName="TextContainer" Property="Grid.Column" Value="0"/> |
| 119 | <Setter TargetName="TextContainer" Property="Margin" Value="0,0,10,0"/> |
| 120 | </Trigger> |
| 121 | </ControlTemplate.Triggers> |
| 122 | |
| 123 | </ControlTemplate> |
| 124 | </Setter.Value> |
| 125 | </Setter> |
| 126 | |
| 127 | </Style> |
| 128 | </ResourceDictionary> |