Browse Source

Add contentoff and contentOn to toggleswitch

Add more resource suport
pull/4069/head
JamRemco 6 years ago
parent
commit
78993eb33c
  1. 115
      src/Avalonia.Controls/ToggleSwitch.cs
  2. 7
      src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml
  3. 10
      src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml
  4. 465
      src/Avalonia.Themes.Fluent/ToggleSwitch.xaml

115
src/Avalonia.Controls/ToggleSwitch.cs

@ -1,16 +1,119 @@
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Controls.Mixins;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Templates;
using Avalonia.LogicalTree;
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
/// <summary> /// <summary>
/// A WinUi like ToggleSwitch control. /// A WinUi like ToggleSwitch control.
/// </summary> /// </summary>
///
public class ToggleSwitch : ToggleButton public class ToggleSwitch : ToggleButton
{ {
} public static readonly StyledProperty<object> OffContentProperty =
AvaloniaProperty.Register<ToggleSwitch, object>(nameof(OffContent));
public static readonly StyledProperty<IDataTemplate> OffContentTemplateProperty =
AvaloniaProperty.Register<ToggleSwitch, IDataTemplate>(nameof(OffContentTemplate));
public static readonly StyledProperty<object> OnContentProperty =
AvaloniaProperty.Register<ToggleSwitch, object>(nameof(OnContent));
public static readonly StyledProperty<IDataTemplate> OnContentTemplateProperty =
AvaloniaProperty.Register<ToggleSwitch, IDataTemplate>(nameof(OnContentTemplate));
public object OnContent
{
get { return GetValue(OnContentProperty); }
set { SetValue(OnContentProperty, value); }
}
public object OffContent
{
get { return GetValue(OffContentProperty); }
set { SetValue(OffContentProperty, value); }
}
public IContentPresenter OffContentPresenter
{
get;
private set;
}
public IContentPresenter OnContentPresenter
{
get;
private set;
}
public IDataTemplate OffContentTemplate
{
get { return GetValue(OffContentTemplateProperty); }
set { SetValue(OffContentTemplateProperty, value); }
}
public IDataTemplate OnContentTemplate
{
get { return GetValue(OnContentTemplateProperty); }
set { SetValue(OnContentTemplateProperty, value); }
}
private void OffContentChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
}
if (e.NewValue is ILogical newChild)
{
LogicalChildren.Add(newChild);
}
}
private void OnContentChanged(AvaloniaPropertyChangedEventArgs e)
{
if (e.OldValue is ILogical oldChild)
{
LogicalChildren.Remove(oldChild);
}
if (e.NewValue is ILogical newChild)
{
LogicalChildren.Add(newChild);
}
}
static ToggleSwitch()
{
OffContentProperty.Changed.AddClassHandler<ToggleSwitch>((x, e) => x.OffContentChanged(e));
OnContentProperty.Changed.AddClassHandler<ToggleSwitch>((x, e) => x.OnContentChanged(e));
}
protected override bool RegisterContentPresenter(IContentPresenter presenter)
{
var result = base.RegisterContentPresenter(presenter);
if (presenter.Name == "Part_OnContentPresenter")
{
OnContentPresenter = presenter;
result = true;
}
if (presenter.Name == "PART_OffContentPresenter")
{
OffContentPresenter = presenter;
result = true;
}
return result;
}
}
} }
/********** Todo ***********
*
* Implement ContenOff property
* Implement ContentOn property.
*/

7
src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml

@ -346,8 +346,10 @@
<!--ToggleSwitch--> <!--ToggleSwitch-->
<x:Double x:Key="ToggleSwitchOnStrokeThickness">0</x:Double> <!--<x:Double x:Key="ToggleSwitchOnStrokeThickness">0</x:Double>-->
<x:Double x:Key="ToggleSwitchOuterBorderStrokeThickness">1</x:Double> <Thickness x:Key="ToggleSwitchOnStrokeThickness">0</Thickness>
<!--<x:Double x:Key="ToggleSwitchOuterBorderStrokeThickness">1</x:Double>-->
<Thickness x:Key="ToggleSwitchOuterBorderStrokeThickness">1</Thickness>
<StaticResource x:Key="ToggleSwitchContentForeground" ResourceKey="SystemControlForegroundBaseHighBrush" /> <StaticResource x:Key="ToggleSwitchContentForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="ToggleSwitchContentForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" /> <StaticResource x:Key="ToggleSwitchContentForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="ToggleSwitchHeaderForeground" ResourceKey="SystemControlForegroundBaseHighBrush" /> <StaticResource x:Key="ToggleSwitchHeaderForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
@ -380,7 +382,6 @@
<StaticResource x:Key="ToggleSwitchKnobFillOnPointerOver" ResourceKey="SystemControlHighlightChromeWhiteBrush" /> <StaticResource x:Key="ToggleSwitchKnobFillOnPointerOver" ResourceKey="SystemControlHighlightChromeWhiteBrush" />
<StaticResource x:Key="ToggleSwitchKnobFillOnPressed" ResourceKey="SystemControlHighlightAltChromeWhiteBrush" /> <StaticResource x:Key="ToggleSwitchKnobFillOnPressed" ResourceKey="SystemControlHighlightAltChromeWhiteBrush" />
<StaticResource x:Key="ToggleSwitchKnobFillOnDisabled" ResourceKey="SystemControlPageBackgroundBaseLowBrush" /> <StaticResource x:Key="ToggleSwitchKnobFillOnDisabled" ResourceKey="SystemControlPageBackgroundBaseLowBrush" />
<SolidColorBrush x:Key="ToggleSwitchCurtainBackgroundThemeBrush" Color="#FF5729C1" /> <SolidColorBrush x:Key="ToggleSwitchCurtainBackgroundThemeBrush" Color="#FF5729C1" />
<SolidColorBrush x:Key="ToggleSwitchCurtainDisabledBackgroundThemeBrush" Color="Transparent" /> <SolidColorBrush x:Key="ToggleSwitchCurtainDisabledBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ToggleSwitchCurtainPointerOverBackgroundThemeBrush" Color="#FF6E46CA" /> <SolidColorBrush x:Key="ToggleSwitchCurtainPointerOverBackgroundThemeBrush" Color="#FF6E46CA" />

10
src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml

@ -345,8 +345,12 @@
<SolidColorBrush x:Key="RadioButtonContentPointerOverForegroundThemeBrush" Color="{DynamicResource SystemColorHighlightTextColor}" /> <SolidColorBrush x:Key="RadioButtonContentPointerOverForegroundThemeBrush" Color="{DynamicResource SystemColorHighlightTextColor}" />
<!--Recources ToggleSwitch--> <!--Recources ToggleSwitch-->
<x:Double x:Key="ToggleSwitchOnStrokeThickness">0</x:Double> <!--<x:Double x:Key="ToggleSwitchOnStrokeThickness">0</x:Double>-->
<x:Double x:Key="ToggleSwitchOuterBorderStrokeThickness">1</x:Double>
<Thickness x:Key="ToggleSwitchOnStrokeThickness">0</Thickness>
<!--<x:Double x:Key="ToggleSwitchOuterBorderStrokeThickness">1</x:Double>-->
<Thickness x:Key="ToggleSwitchOuterBorderStrokeThickness">1</Thickness>
<StaticResource x:Key="ToggleSwitchContentForeground" ResourceKey="SystemControlForegroundBaseHighBrush" /> <StaticResource x:Key="ToggleSwitchContentForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
<StaticResource x:Key="ToggleSwitchContentForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" /> <StaticResource x:Key="ToggleSwitchContentForegroundDisabled" ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="ToggleSwitchHeaderForeground" ResourceKey="SystemControlForegroundBaseHighBrush" /> <StaticResource x:Key="ToggleSwitchHeaderForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
@ -379,7 +383,6 @@
<StaticResource x:Key="ToggleSwitchKnobFillOnPointerOver" ResourceKey="SystemControlHighlightChromeWhiteBrush" /> <StaticResource x:Key="ToggleSwitchKnobFillOnPointerOver" ResourceKey="SystemControlHighlightChromeWhiteBrush" />
<StaticResource x:Key="ToggleSwitchKnobFillOnPressed" ResourceKey="SystemControlHighlightAltChromeWhiteBrush" /> <StaticResource x:Key="ToggleSwitchKnobFillOnPressed" ResourceKey="SystemControlHighlightAltChromeWhiteBrush" />
<StaticResource x:Key="ToggleSwitchKnobFillOnDisabled" ResourceKey="SystemControlPageBackgroundBaseLowBrush" /> <StaticResource x:Key="ToggleSwitchKnobFillOnDisabled" ResourceKey="SystemControlPageBackgroundBaseLowBrush" />
<SolidColorBrush x:Key="ToggleSwitchCurtainBackgroundThemeBrush" Color="#FF4617B4" /> <SolidColorBrush x:Key="ToggleSwitchCurtainBackgroundThemeBrush" Color="#FF4617B4" />
<SolidColorBrush x:Key="ToggleSwitchCurtainDisabledBackgroundThemeBrush" Color="Transparent" /> <SolidColorBrush x:Key="ToggleSwitchCurtainDisabledBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ToggleSwitchCurtainPointerOverBackgroundThemeBrush" Color="#FF5F37BE" /> <SolidColorBrush x:Key="ToggleSwitchCurtainPointerOverBackgroundThemeBrush" Color="#FF5F37BE" />
@ -404,6 +407,5 @@
<SolidColorBrush x:Key="ToggleSwitchTrackPointerOverBackgroundThemeBrush" Color="#4A000000" /> <SolidColorBrush x:Key="ToggleSwitchTrackPointerOverBackgroundThemeBrush" Color="#4A000000" />
<SolidColorBrush x:Key="ToggleSwitchTrackPressedBackgroundThemeBrush" Color="#42000000" /> <SolidColorBrush x:Key="ToggleSwitchTrackPressedBackgroundThemeBrush" Color="#42000000" />
</Style.Resources> </Style.Resources>
</Style> </Style>

465
src/Avalonia.Themes.Fluent/ToggleSwitch.xaml

@ -4,7 +4,7 @@
xmlns:sys="clr-namespace:System;assembly=netstandard"> xmlns:sys="clr-namespace:System;assembly=netstandard">
<Design.PreviewWith> <Design.PreviewWith>
<StackPanel Margin="20" Width="250" Spacing="24"> <StackPanel Margin="20" Width="250" Spacing="24" >
<StackPanel Spacing="12"> <StackPanel Spacing="12">
<TextBlock <TextBlock
@ -13,8 +13,10 @@
<TextBlock <TextBlock
Text="Updates will be automaticly Downloaded and installed shile the computer is shutting down or restarting" Text="Updates will be automaticly Downloaded and installed shile the computer is shutting down or restarting"
TextWrapping="Wrap"/> TextWrapping="Wrap"/>
<ToggleSwitch Content="Enable automatic Updates?" <ToggleSwitch
FontWeight="Medium" Content="Enable automatic Updates?"
OffContent="Uit"
OnContent="Aan"
VerticalAlignment="Bottom" /> VerticalAlignment="Bottom" />
</StackPanel> </StackPanel>
@ -26,244 +28,289 @@
Text="The previewer Shows a preview off your code, this could slow down your system" Text="The previewer Shows a preview off your code, this could slow down your system"
TextWrapping="Wrap"/> TextWrapping="Wrap"/>
<ToggleSwitch <ToggleSwitch
OnContent="Yes" OffContent="No"
Content="Previewer" Content="Previewer"
IsChecked="True" IsChecked="True"
FontWeight="Medium"/> />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</Design.PreviewWith> </Design.PreviewWith>
<Style Selector="ToggleSwitch">
<Style Selector=":is(ToggleSwitch)"> <Setter Property="Foreground" Value="{DynamicResource ToggleSwitchContentForeground}" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<!--<Setter Property="ManipulationMode" Value="System,TranslateX" />
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
<Setter Property="FocusVisualMargin" Value="-7,-3,-7,-3" />-->
<Setter Property="Template">
<ControlTemplate>
<Grid
Background="{TemplateBinding Background}"
RowDefinitions="Auto,*">
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" /> <ContentPresenter x:Name="PART_ContentPresenter"
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" /> Grid.Row="0"
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" /> Content="{TemplateBinding Content}"
<Setter Property="MinWidth" Value="72"/> ContentTemplate="{TemplateBinding ContentTemplate}"
<Setter Property="MinHeight" Value="32"/>
Margin="{DynamicResource ToggleSwitchTopHeaderMargin}"
VerticalAlignment="Top"/>
<Setter Property="Template"> <Grid
<ControlTemplate> Grid.Row="1"
<Grid MinWidth="{StaticResource ToggleSwitchThemeMinWidth}"
ColumnDefinitions="Auto,*" HorizontalAlignment="Left"
RowDefinitions="22,auto"> VerticalAlignment="Top">
<Canvas
Height="24"
Grid.Row="1"
Grid.Column="0">
<Border <Grid.RowDefinitions>
Name="PART_BorderBackground" <RowDefinition Height="{DynamicResource ToggleSwitchPreContentMargin}" />
Height="20" Width="44" <RowDefinition Height="Auto" />
Canvas.Top="2" <RowDefinition Height="{DynamicResource ToggleSwitchPostContentMargin}" />
Canvas.Left="0" </Grid.RowDefinitions>
BorderThickness="1.5"
CornerRadius="100"/>
<Ellipse <Grid.ColumnDefinitions>
Name="PART_CircleThumb" <ColumnDefinition Width="Auto" />
Height="10" Width="10" <ColumnDefinition Width="12" MaxWidth="12" />
Canvas.Top="7"/> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ContentControl <Grid x:Name="SwitchAreaGrid"
Name="PART_TextBooleanValue"
Canvas.Left="54"
VerticalContentAlignment="Bottom"
Height="20"/>
</Canvas>
<ContentPresenter Grid.RowSpan="3"
Name="PART_ContentPresenter" Grid.ColumnSpan="3"
ContentTemplate="{TemplateBinding ContentTemplate}" Margin="0,5"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}" Background="{DynamicResource ToggleSwitchContainerBackground}" />
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" <ContentPresenter x:Name="PART_OffContentPresenter"
Background="Transparent" Grid.RowSpan="3"
IsVisible="{TemplateBinding Content, Converter={x:Static ObjectConverters.IsNotNull}}" Grid.Column="2"
Grid.Row="0" Grid.Column="0"/>
</Grid>
Content="{TemplateBinding OffContent}"
ContentTemplate="{TemplateBinding OffContentTemplate}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
/>
<ContentPresenter x:Name="PART_OnContentPresenter"
Grid.RowSpan="3"
Grid.Column="2"
Content="{TemplateBinding OnContent}"
ContentTemplate="{TemplateBinding OnContentTemplate}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
/>
<Border x:Name="OuterBorder"
Grid.Row="1"
Height="20"
Width="40"
CornerRadius="50"
Background="{DynamicResource ToggleSwitchFilloff}"
BorderBrush="{DynamicResource ToggleSwitchStrokeOn}"
BorderThickness="{DynamicResource ToggleSwitchOuterBorderStrokeThickness}" />
<Border x:Name="SwitchKnobBounds"
Grid.Row="1"
Height="20"
Width="40"
CornerRadius="50"
Background="{DynamicResource ToggleSwitchFillOn}"
BorderBrush="{DynamicResource ToggleSwitchStrokeOn}"
BorderThickness="{DynamicResource ToggleSwitchOnStrokeThickness}"
/>
<Grid x:Name="SwitchKnob"
Grid.Row="1"
HorizontalAlignment="Left"
Width="20"
Height="20">
<Ellipse x:Name="SwitchKnobOn"
Fill="{DynamicResource ToggleSwitchKnobFillOn}"
Width="10"
Height="10"
/>
<Ellipse x:Name="SwitchKnobOff"
Fill="{DynamicResource ToggleSwitchKnobFillOff}"
Width="10"
Height="10" />
<Grid.RenderTransform>
<!--<TranslateTransform x:Name="KnobTranslateTransform" />-->
</Grid.RenderTransform>
</Grid>
<Thumb x:Name="SwitchThumb"
Grid.RowSpan="3"
Grid.ColumnSpan="3">
<Thumb.Template>
<ControlTemplate>
<Rectangle Fill="Transparent" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Grid>
</Grid>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</Style> </Style>
<!--******** POINTEROVER *******-->
<Style Selector="ToggleSwitch:PointerOver /template/ Border#OuterBorder">
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOffPointerOver}"/>
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOffPointerOver}"/>
</Style>
<Style Selector="ToggleSwitch:PointerOver /template/ Ellipse#SwitchKnobOff">
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOffPointerOver}"/>
</Style>
<Style Selector="ToggleSwitch:PointerOver /template/ Ellipse#SwitchKnobOn">
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOnPointerOver}"/>
</Style>
<!--Position Transition Thump--> <Style Selector="ToggleSwitch:PointerOver /template/ Border#SwitchKnobBounds">
<Style Selector="ToggleSwitch /template/ Ellipse#PART_CircleThumb"> <Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnPointerOver}"/>
<Setter Property="Canvas.Left" Value="{DynamicResource ThumbLeft}"/> <Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnPointerOver}"/>
<Setter Property="Fill" Value="White" /> </Style>
<Setter Property="Transitions">
<Transitions> <Style Selector="ToggleSwitch:PointerOver /template/ Grid#SwitchAreaGrid">
<DoubleTransition Property="Canvas.Left" Duration="0:0:0.4" Easing="CubicEaseOut"/> <Setter Property="Background" Value="{DynamicResource ToggleSwitchContainerBackgroundPointerOver}"/>
</Transitions> </Style>
</Setter>
</Style>
<!--Color thumbAnimation Off--> <!--******** PRESSED *******-->
<Style Selector="ToggleSwitch:unchecked /template/ Ellipse#PART_CircleThumb">
<Setter Property="Canvas.Left" Value="{DynamicResource ThumbLeft}"/> <!--psition animation is handled by transition--> <Style Selector="ToggleSwitch:pressed /template/ Border#OuterBorder">
<Style.Animations> <Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOffPressed}"/>
<Animation Duration="0:0:0.35" FillMode="Forward" Easing="CubicEaseOut" > <Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOffPressed}"/>
<KeyFrame Cue="0%"> </Style>
<Setter Property="Fill" Value="White"/>
</KeyFrame> <Style Selector="ToggleSwitch:pressed /template/ Border#SwitchKnobBounds">
<KeyFrame Cue="100%"> <Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnPressed}"/>
<Setter Property="Fill" Value="Royalblue"/> <Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnPressed}"/>
</KeyFrame> </Style>
</Animation>
</Style.Animations> <Style Selector="ToggleSwitch:pressed /template/ Ellipse#SwitchKnobOff">
</Style> <Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOffPressed}"/>
</Style>
<Style Selector="ToggleSwitch:pressed /template/ Ellipse#SwitchKnobOn">
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOnPressed}"/>
</Style>
<Style Selector="ToggleSwitch:pressed /template/ Grid#SwitchAreaGrid">
<Setter Property="Background" Value="{DynamicResource ToggleSwitchContainerBackgroundPressed}"/>
</Style>
<!--******** DISABLED *******-->
<!--color thumbAnimation Onn--> <Style Selector="ToggleSwitch:disabled">
<Style Selector="ToggleSwitch:checked /template/ Ellipse#PART_CircleThumb"> <Setter Property="Foreground" Value="{DynamicResource ToggleSwitchHeaderForegroundDisabled}"/>
<Setter Property="Canvas.Left" Value="{DynamicResource ThumbRight}"/> <!--psition animation is handled by transition--> </Style>
<Style.Animations>
<Animation Duration="0:0:0.4" FillMode="Forward" Easing="CubicEaseOut"> <Style Selector="ToggleSwitch:disabled /template/ Border#OuterBorder">
<KeyFrame Cue="0%"> <Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOffDisabled}"/>
<Setter Property="Fill" Value="Royalblue"/> <Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOffPressed}"/>
</KeyFrame> </Style>
<KeyFrame Cue="100%">
<Setter Property="Fill" Value="White"/> <Style Selector="ToggleSwitch:disabled /template/ Ellipse#SwitchKnobOff">
</KeyFrame> <Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOffDisabled}"/>
</Animation> </Style>
</Style.Animations>
</Style> <Style Selector="ToggleSwitch:disabled /template/ Ellipse#SwitchKnobOn">
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOnDisabled}"/>
</Style>
<!--color BackGround Animation Off--> <Style Selector="ToggleSwitch:disabled /template/ Border#SwitchKnobBounds">
<Style Selector="ToggleSwitch /template/ Border#PART_BorderBackground"> <Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnDisabled}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOff}"/> <Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnDisabled}"/>
</Style> </Style>
<Style Selector="ToggleSwitch:unchecked /template/ Border#PART_BorderBackground"> <Style Selector="ToggleSwitch:disabled /template/ Grid#SwitchAreaGrid">
<Style.Animations> <Setter Property="Background" Value="{DynamicResource BackgroundDisabled}"/>
<Animation Duration="0:0:0.5" FillMode="Forward" Easing="CubicEaseOut"> </Style>
<KeyFrame Cue="0%">
<Setter Property="Background" Value="Royalblue"/>
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Background" Value="White"/>
</KeyFrame>
</Animation>
</Style.Animations>
<!--<Setter Property="BorderBrush" Value="Royalblue"/>-->
</Style>
<!--color BackGrounf Animation On-->
<Style Selector="ToggleSwitch:checked /template/ Border#PART_BorderBackground">
<Style.Animations>
<Animation Duration="0:0:0.4" FillMode="Forward" Easing="CubicEaseOut">
<KeyFrame Cue="0%">
<Setter Property="Background" Value="white"/>
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Background" Value="Royalblue"/>
</KeyFrame>
</Animation>
</Style.Animations>
<!--<Setter Property="BorderBrush" Value="Royalblue"/>-->
</Style>
<!--<Style Selector="ToggleSwitch /template/ Border#PART_BorderBackground"> <!--******** CHECKED *******-->
<Setter Property="Opacity" Value="100" /> <Style Selector="ToggleSwitch:checked /template/ Border#OuterBorder">
<Setter Property="Transitions"> <Setter Property="Opacity" Value="1"/>
<Transitions> </Style>
<DoubleTransition Property="Opacity" Duration="0:0:0.2" Easing="CubicEaseOut"/>
</Transitions> <Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobOff">
</Setter> <Setter Property="Opacity" Value="0"/>
</Style>--> <!--<Setter Property="IsHitTestVisible" Value="false"/>-->
</Style>
<Style Selector="ToggleSwitch:checked /template/ Border#SwitchKnobBounds">
<Setter Property="Opacity" Value="0"/>
<!--<Setter Property="IsHitTestVisible" Value="false"/>-->
</Style>
<!--Setting the On/Of Text. This might be changed in the near future --> <Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobOn">
<Style Selector="ToggleSwitch:checked /template/ ContentControl#PART_TextBooleanValue"> <Setter Property="Opacity" Value="1"/>
<Setter Property="Content" Value="On"/> <!--<Setter Property="IsHitTestVisible" Value="true"/>-->
</Style> </Style>
<Style Selector="ToggleSwitch:unchecked /template/ ContentControl#PART_TextBooleanValue">
<Setter Property="Content" Value="Off"/>
</Style>
<!--border BackGround MouseOver-->
<Style Selector="ToggleSwitch /template/ Border#PART_BorderBackground:pointerover">
<Setter Property="BorderBrush" Value="cornflowerblue"/>
</Style>
<!--BackGround Mouseover and checked--> <Style Selector="ToggleSwitch:checked /template/ ContentPresenter#PART_OffContentPresenter">
<!--<Style Selector="ToggleSwitch:checked /template/ Border#PART_BorderBackground:pointerover"> <Setter Property="Opacity" Value="0"/>
<Setter Property="Opacity" Value="50"/> <!--<Setter Property="IsHitTestVisible" Value="false"/>-->
</Style>--> </Style>
<!--Border -BackGround Focus and checkred--> <Style Selector="ToggleSwitch:checked /template/ ContentPresenter#PART_OnContentPresenter">
<Style Selector="ToggleSwitch:focus:checked /template/ Border#PART_BorderBackground"> <Setter Property="Opacity" Value="1"/>
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOn}"/> <!--<Setter Property="IsHitTestVisible" Value="true"/>-->
</Style> </Style>
<!--Border -BackGround Focus and uncheckred-->
<Style Selector="ToggleSwitch:focus:unchecked /template/ Border#PART_BorderBackground">
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchFillOn}"/>
</Style>
<!--BackGround Focus + Mouseover-->
<Style Selector="ToggleSwitch:focus /template/ Border#PART_BorderBackground:pointerover">
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnPointerOver}"/>
</Style>
<!--Control disabled-->
<Style Selector="ToggleSwitch:disabled">
<Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}"/>
</Style>
<!--******** UNCHECKED *******-->
<!--****** PRESSED ******-->
<!--Because of a bug in color animation flikkering apears -->
<!--Implement later-->
<!--<Style Selector="ToggleSwitch:pressed /template/ Border#PART_BorderBackground">
<Style.Animations>
<Animation Duration="0:0:0.1" FillMode="Forward" Easing="CubicEaseOut">
<KeyFrame Cue="100%">
<Setter Property="Background" Value="Gray"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>-->
<!--****** iNDETERMINATE ******-->
<!--What should i do here?-->
<!--<Style Selector="ToggleSwitch:indeterminate /template/ ContentControl#PART_TextBooleanValue"> <Style Selector="ToggleSwitch:checked /template/ Border#OuterBorder">
<Setter Property="Content" Value="Not set"/> <Setter Property="Opacity" Value="1"/>
</Style>--> </Style>
<Style Selector="ToggleSwitch:indeterminate /template/ Border#PART_BorderBackground"> <Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobOff">
<Setter Property="Background" Value="White"/> <Setter Property="Opacity" Value="1"/>
</Style> </Style>
<Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobOn">
<!--******** Mouse over of checked state *********--> <Setter Property="Opacity" Value="0"/>
<!--Because of a bug in color animation flikkering apears --> </Style>
<!--Implement later-->
<!--<Style Selector="ToggleSwitch:checked /template/ Border#PART_BorderBackground:pointerover"> <Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobBounds">
<Style.Animations> <Setter Property="Opacity" Value="1"/>
<Animation Duration="0:0:0.1" FillMode="Forward" Easing="CubicEaseOut"> <!--<Setter Property="IsHitTestVisible" Value="false"/>-->
</Style>
<KeyFrame Cue="100%">
<Setter Property="Background" Value="cornflowerblue"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>-->
<Style Selector="ToggleSwitch:checked /template/ ContentPresenter#PART_OffContentPresenter">
<Setter Property="Opacity" Value="1"/>
</Style>
<Style Selector="ToggleSwitch:checked /template/ ContentPresenter#PART_OnContentPresenter">
<Setter Property="Opacity" Value="0"/>
<Styles.Resources>
<sys:Double x:Key="ThumbLeft">5</sys:Double> </Style>
<sys:Double x:Key="ThumbRight">28</sys:Double>
<Color x:Key="ColorFILLOn">RoyalBlue</Color> <!--Animating a color via a resource does not work!-->
<Color x:Key="ColorFILLOff">White</Color> <!-- "" --> <Styles.Resources>
<Thickness x:Key="ToggleSwitchTopHeaderMargin">0,0,0,6</Thickness>
</Styles.Resources> <x:Double x:Key="ToggleSwitchPreContentMargin">6</x:Double>
<x:Double x:Key="ToggleSwitchPostContentMargin">6</x:Double>
<x:Double x:Key="ToggleSwitchThemeMinWidth">154</x:Double>
<x:Double x:Key="KnobOnPosition">5</x:Double>
<x:Double x:Key="KnobOffPosition">28</x:Double>
</Styles.Resources>
</Styles> </Styles>

Loading…
Cancel
Save