Files
Speckle.Material.Avalonia/Material.Styles/ToggleSwitch.xaml
T

207 lines
10 KiB
XML

<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:assists="clr-namespace:Material.Styles.Assists"
xmlns:system="clr-namespace:System;assembly=netstandard">
<Styles.Resources>
<system:Double x:Key="RippleHoveredOpacity">0.12</system:Double>
<system:Double x:Key="RipplePressedOpacity">0.26</system:Double>
</Styles.Resources>
<Style Selector="ToggleSwitch">
<Setter Property="TextBlock.Foreground" Value="{DynamicResource MaterialDesignBody}" />
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}" />
<Setter Property="assists:ToggleSwitchAssist.SwitchTrackOnBackground"
Value="{DynamicResource PrimaryHueLightBrush}" />
<Setter Property="assists:ToggleSwitchAssist.SwitchTrackOffBackground"
Value="Black" />
<Setter Property="assists:ToggleSwitchAssist.SwitchThumbOnBackground"
Value="{DynamicResource PrimaryHueMidBrush}" />
<Setter Property="assists:ToggleSwitchAssist.SwitchThumbOffBackground"
Value="{DynamicResource MaterialDesignBody}" />
<Setter Property="assists:ShadowAssist.ShadowDepth" Value="Depth1" />
<Setter Property="assists:SelectionControlAssist.Size" Value="36" />
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="ClipToBounds" Value="False" />
<Setter Property="OffContent" Value="{x:Null}" />
<Setter Property="Template">
<ControlTemplate>
<Border Name="PART_RootBorder"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<DockPanel Name="PART_RootPanel">
<Viewbox Width="{TemplateBinding (assists:SelectionControlAssist.Size)}"
Stretch="Uniform"
ClipToBounds="False"
VerticalAlignment="Center">
<Panel Name="PART_Switch">
<Border Name="PART_TrackSwitch"
Width="36"
Height="14"
Opacity="0.26"
CornerRadius="7"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
<Canvas Name="SwitchKnob"
Width="16" Height="20"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<Panel Name="MovingKnobs"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Width="20" Height="20">
<Ellipse Name="RippleThumb"
Width="42" Height="42"
Margin="-100" VerticalAlignment="Center" HorizontalAlignment="Center" />
<AdornerLayer>
<Border Name="Thumb"
CornerRadius="10"
Width="20" Height="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
assists:ShadowAssist.ShadowDepth="{TemplateBinding (assists:ShadowAssist.ShadowDepth)}" >
<Panel Name="PART_ThumbContentContainer">
<ContentPresenter Name="OnContentPresenter"
Content="{TemplateBinding OnContent}"
ContentTemplate="{TemplateBinding OnContentTemplate}" />
<ContentPresenter Name="OffContentPresenter"
Content="{TemplateBinding OffContent}"
ContentTemplate="{TemplateBinding OffContentTemplate}" />
</Panel>
</Border>
</AdornerLayer>
</Panel>
</Canvas>
</Panel>
</Viewbox>
<ContentPresenter Name="PART_ContentPresenter"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</DockPanel>
</Border>
</ControlTemplate>
</Setter>
</Style>
<!-- RightToLeft content variant -->
<Style Selector="ToggleSwitch.LeftHeader">
<Setter Property="Padding" Value="0 0 8 0" />
</Style>
<Style Selector="ToggleSwitch.LeftHeader /template/ DockPanel#PART_RootPanel > Viewbox">
<Setter Property="DockPanel.Dock" Value="Right" />
</Style>
<!-- Transitions -->
<Style Selector="ToggleSwitch:not(.no-transitions) /template/ Border#PART_TrackSwitch,
ToggleSwitch:not(.no-transitions) /template/ Border#Thumb">
<Setter Property="Transitions">
<Transitions>
<BrushTransition Property="Background" Duration="0.25" Easing="CircularEaseOut"/>
</Transitions>
</Setter>
</Style>
<Style Selector="ToggleSwitch:not(.no-transitions):not(:dragging) /template/ Panel#MovingKnobs">
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="Canvas.Left" Duration="0.25" Easing="CircularEaseOut" />
</Transitions>
</Setter>
</Style>
<!-- Default state -->
<Style Selector="ToggleSwitch /template/ ContentPresenter#OnContentPresenter">
<Setter Property="IsVisible" Value="False" />
</Style>
<Style Selector="ToggleSwitch /template/ Border#Thumb">
<Setter Property="Background"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(assists:ToggleSwitchAssist.SwitchThumbOffBackground)}" />
</Style>
<Style Selector="ToggleSwitch /template/ Border#PART_TrackSwitch">
<Setter Property="Background"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(assists:ToggleSwitchAssist.SwitchTrackOffBackground)}" />
</Style>
<!-- On checked state -->
<Style Selector="ToggleSwitch:checked /template/ ContentPresenter#OffContentPresenter">
<Setter Property="IsVisible" Value="False" />
</Style>
<Style Selector="ToggleSwitch:checked /template/ Border#Thumb">
<Setter Property="Background"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(assists:ToggleSwitchAssist.SwitchThumbOnBackground)}" />
</Style>
<Style Selector="ToggleSwitch:checked /template/ Border#PART_TrackSwitch">
<Setter Property="Background"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(assists:ToggleSwitchAssist.SwitchTrackOnBackground)}" />
</Style>
<!-- Accent variant -->
<Style Selector="ToggleSwitch.Accent">
<Setter Property="assists:ToggleSwitchAssist.SwitchTrackOnBackground"
Value="{DynamicResource SecondaryHueLightBrush}" />
<Setter Property="assists:ToggleSwitchAssist.SwitchThumbOnBackground"
Value="{DynamicResource SecondaryHueMidBrush}" />
</Style>
<!-- On disabled state -->
<Style Selector="ToggleSwitch:disabled /template/ Border#PART_RootBorder">
<Setter Property="Opacity" Value="0.23" />
</Style>
<!-- Override Avalonia.Themes.Default parameter -->
<!-- Issue: https://github.com/AvaloniaCommunity/Material.Avalonia/issues/132 -->
<Style Selector="ToggleSwitch:disabled">
<Setter Property="TextBlock.Foreground" Value="{DynamicResource MaterialDesignBody}" />
<Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}" />
</Style>
<!-- Another fix -->
<Style Selector="ToggleSwitch /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Margin" Value="0"/>
</Style>
<!-- Ripple effect -->
<Style Selector="ToggleSwitch /template/ Ellipse#RippleThumb">
<Setter Property="Opacity" Value="0" />
<Setter Property="Fill"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(assists:ToggleSwitchAssist.SwitchThumbOffBackground)}" />
</Style>
<Style Selector="ToggleSwitch:pointerover /template/ Ellipse#RippleThumb">
<Setter Property="Opacity" Value="{StaticResource RippleHoveredOpacity}" />
</Style>
<Style Selector="ToggleSwitch:pressed /template/ Ellipse#RippleThumb">
<Setter Property="Opacity" Value="{StaticResource RipplePressedOpacity}" />
</Style>
<Style Selector="ToggleSwitch:checked /template/ Ellipse#RippleThumb">
<Setter Property="Fill"
Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(assists:ToggleSwitchAssist.SwitchThumbOnBackground)}" />
</Style>
</Styles>