29 changed files with 1729 additions and 451 deletions
@ -1,136 +0,0 @@ |
|||
// (c) Copyright Microsoft Corporation.
|
|||
// This source is subject to the Microsoft Public License (Ms-PL).
|
|||
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
|
|||
// All other rights reserved.
|
|||
|
|||
using System; |
|||
|
|||
namespace Avalonia.Controls.Utils |
|||
{ |
|||
internal static class DoubleUtil |
|||
{ |
|||
internal const double DBL_EPSILON = 1e-6; |
|||
|
|||
/// <summary>
|
|||
/// AreClose - Returns whether or not two doubles are "close". That is, whether or
|
|||
/// not they are within epsilon of each other. Note that this epsilon is proportional
|
|||
/// to the numbers themselves to that AreClose survives scalar multiplication.
|
|||
/// There are plenty of ways for this to return false even for numbers which
|
|||
/// are theoretically identical, so no code calling this should fail to work if this
|
|||
/// returns false. This is important enough to repeat:
|
|||
/// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
|
|||
/// used for optimizations *only*.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// bool - the result of the AreClose comparison.
|
|||
/// </returns>
|
|||
/// <param name="value1"> The first double to compare. </param>
|
|||
/// <param name="value2"> The second double to compare. </param>
|
|||
public static bool AreClose(double value1, double value2) |
|||
{ |
|||
//in case they are Infinities (then epsilon check does not work)
|
|||
if (value1 == value2) return true; |
|||
// This computes (|value1-value2| / (|value1| + |value2| + 10.0)) < DBL_EPSILON
|
|||
double eps = (Math.Abs(value1) + Math.Abs(value2) + 10.0) * DBL_EPSILON; |
|||
double delta = value1 - value2; |
|||
return (-eps < delta) && (eps > delta); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// GreaterThan - Returns whether or not the first double is greater than the second double.
|
|||
/// That is, whether or not the first is strictly greater than *and* not within epsilon of
|
|||
/// the other number. Note that this epsilon is proportional to the numbers themselves
|
|||
/// to that AreClose survives scalar multiplication. Note,
|
|||
/// There are plenty of ways for this to return false even for numbers which
|
|||
/// are theoretically identical, so no code calling this should fail to work if this
|
|||
/// returns false. This is important enough to repeat:
|
|||
/// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
|
|||
/// used for optimizations *only*.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// bool - the result of the GreaterThan comparison.
|
|||
/// </returns>
|
|||
/// <param name="value1"> The first double to compare. </param>
|
|||
/// <param name="value2"> The second double to compare. </param>
|
|||
public static bool GreaterThan(double value1, double value2) |
|||
{ |
|||
return (value1 > value2) && !AreClose(value1, value2); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// GreaterThanOrClose - Returns whether or not the first double is greater than or close to
|
|||
/// the second double. That is, whether or not the first is strictly greater than or within
|
|||
/// epsilon of the other number. Note that this epsilon is proportional to the numbers
|
|||
/// themselves to that AreClose survives scalar multiplication. Note,
|
|||
/// There are plenty of ways for this to return false even for numbers which
|
|||
/// are theoretically identical, so no code calling this should fail to work if this
|
|||
/// returns false. This is important enough to repeat:
|
|||
/// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
|
|||
/// used for optimizations *only*.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// bool - the result of the GreaterThanOrClose comparison.
|
|||
/// </returns>
|
|||
/// <param name="value1"> The first double to compare. </param>
|
|||
/// <param name="value2"> The second double to compare. </param>
|
|||
public static bool GreaterThanOrClose(double value1, double value2) |
|||
{ |
|||
return (value1 > value2) || AreClose(value1, value2); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// IsZero - Returns whether or not the double is "close" to 0. Same as AreClose(double, 0),
|
|||
/// but this is faster.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// bool - the result of the IsZero comparison.
|
|||
/// </returns>
|
|||
/// <param name="value"> The double to compare to 0. </param>
|
|||
public static bool IsZero(double value) |
|||
{ |
|||
return Math.Abs(value) < 10.0 * DBL_EPSILON; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// LessThan - Returns whether or not the first double is less than the second double.
|
|||
/// That is, whether or not the first is strictly less than *and* not within epsilon of
|
|||
/// the other number. Note that this epsilon is proportional to the numbers themselves
|
|||
/// to that AreClose survives scalar multiplication. Note,
|
|||
/// There are plenty of ways for this to return false even for numbers which
|
|||
/// are theoretically identical, so no code calling this should fail to work if this
|
|||
/// returns false. This is important enough to repeat:
|
|||
/// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
|
|||
/// used for optimizations *only*.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// bool - the result of the LessThan comparison.
|
|||
/// </returns>
|
|||
/// <param name="value1"> The first double to compare. </param>
|
|||
/// <param name="value2"> The second double to compare. </param>
|
|||
public static bool LessThan(double value1, double value2) |
|||
{ |
|||
return (value1 < value2) && !AreClose(value1, value2); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// LessThanOrClose - Returns whether or not the first double is less than or close to
|
|||
/// the second double. That is, whether or not the first is strictly less than or within
|
|||
/// epsilon of the other number. Note that this epsilon is proportional to the numbers
|
|||
/// themselves to that AreClose survives scalar multiplication. Note,
|
|||
/// There are plenty of ways for this to return false even for numbers which
|
|||
/// are theoretically identical, so no code calling this should fail to work if this
|
|||
/// returns false. This is important enough to repeat:
|
|||
/// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
|
|||
/// used for optimizations *only*.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// bool - the result of the LessThanOrClose comparison.
|
|||
/// </returns>
|
|||
/// <param name="value1"> The first double to compare. </param>
|
|||
/// <param name="value2"> The second double to compare. </param>
|
|||
public static bool LessThanOrClose(double value1, double value2) |
|||
{ |
|||
return (value1 < value2) || AreClose(value1, value2); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,105 @@ |
|||
using Avalonia.Controls.Primitives; |
|||
using Avalonia.Controls.Templates; |
|||
using Avalonia.LogicalTree; |
|||
|
|||
namespace Avalonia.Controls |
|||
{ |
|||
/// <summary>
|
|||
/// A Toggle Switch control.
|
|||
/// </summary>
|
|||
public class ToggleSwitch : ToggleButton |
|||
{ |
|||
static ToggleSwitch() |
|||
{ |
|||
OffContentProperty.Changed.AddClassHandler<ToggleSwitch>((x, e) => x.OffContentChanged(e)); |
|||
OnContentProperty.Changed.AddClassHandler<ToggleSwitch>((x, e) => x.OnContentChanged(e)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Defines the <see cref="OffContent"/> property.
|
|||
/// </summary>
|
|||
public static readonly StyledProperty<object> OffContentProperty = |
|||
AvaloniaProperty.Register<ToggleSwitch, object>(nameof(OffContent), defaultValue: "Off"); |
|||
|
|||
/// <summary>
|
|||
/// Defines the <see cref="OffContentTemplate"/> property.
|
|||
/// </summary>
|
|||
public static readonly StyledProperty<IDataTemplate> OffContentTemplateProperty = |
|||
AvaloniaProperty.Register<ToggleSwitch, IDataTemplate>(nameof(OffContentTemplate)); |
|||
|
|||
/// <summary>
|
|||
/// Defines the <see cref="OnContent"/> property.
|
|||
/// </summary>
|
|||
public static readonly StyledProperty<object> OnContentProperty = |
|||
AvaloniaProperty.Register<ToggleSwitch, object>(nameof(OnContent), defaultValue: "On"); |
|||
|
|||
/// <summary>
|
|||
/// Defines the <see cref="OnContentTemplate"/> property.
|
|||
/// </summary>
|
|||
public static readonly StyledProperty<IDataTemplate> OnContentTemplateProperty = |
|||
AvaloniaProperty.Register<ToggleSwitch, IDataTemplate>(nameof(OnContentTemplate)); |
|||
|
|||
/// <summary>
|
|||
/// Gets or Sets the Content that is displayed when in the On State.
|
|||
/// </summary>
|
|||
public object OnContent |
|||
{ |
|||
get { return GetValue(OnContentProperty); } |
|||
set { SetValue(OnContentProperty, value); } |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or Sets the Content that is displayed when in the Off State.
|
|||
/// </summary>
|
|||
public object OffContent |
|||
{ |
|||
get { return GetValue(OffContentProperty); } |
|||
set { SetValue(OffContentProperty, value); } |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or Sets the <see cref="IDataTemplate"/> used to display the <see cref="OffContent"/>.
|
|||
/// </summary>
|
|||
public IDataTemplate OffContentTemplate |
|||
{ |
|||
get { return GetValue(OffContentTemplateProperty); } |
|||
set { SetValue(OffContentTemplateProperty, value); } |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets or Sets the <see cref="IDataTemplate"/> used to display the <see cref="OnContent"/>.
|
|||
/// </summary>
|
|||
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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,294 @@ |
|||
<Styles xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:sys="clr-namespace:System;assembly=netstandard"> |
|||
<Styles.Resources> |
|||
<Thickness x:Key="ToggleSwitchTopHeaderMargin">0,0,0,6</Thickness> |
|||
<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">20</x:Double> |
|||
<x:Double x:Key="KnobOffPosition">0</x:Double> |
|||
</Styles.Resources> |
|||
<Design.PreviewWith> |
|||
<StackPanel Margin="20" Width="250" Spacing="24" > |
|||
<StackPanel Spacing="12" > |
|||
<TextBlock |
|||
Text="Automatic updates" |
|||
Classes="h1"/> |
|||
<TextBlock |
|||
Text="Updates will be automaticly Downloaded and installed shile the computer is shutting down or restarting" |
|||
TextWrapping="Wrap"/> |
|||
<ToggleSwitch HorizontalContentAlignment="Left" |
|||
Content="Enable automatic Updates?" |
|||
OffContent="Uit" |
|||
OnContent="Aan" |
|||
VerticalAlignment="Bottom"/> |
|||
</StackPanel> |
|||
|
|||
<StackPanel Spacing="12"> |
|||
<TextBlock |
|||
Text="Previewer" |
|||
Classes="h1"/> |
|||
<TextBlock |
|||
Text="The previewer Shows a preview off your code, this could slow down your system" |
|||
TextWrapping="Wrap"/> |
|||
<ToggleSwitch |
|||
Content="Previewer" |
|||
IsChecked="True" /> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
</Design.PreviewWith> |
|||
|
|||
<Style Selector="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="Template"> |
|||
<ControlTemplate> |
|||
<Grid Background="{TemplateBinding Background}" |
|||
RowDefinitions="Auto,*"> |
|||
|
|||
<ContentPresenter x:Name="PART_ContentPresenter" |
|||
Grid.Row="0" |
|||
Content="{TemplateBinding Content}" |
|||
ContentTemplate="{TemplateBinding ContentTemplate}" |
|||
Margin="{DynamicResource ToggleSwitchTopHeaderMargin}" |
|||
VerticalAlignment="Top"/> |
|||
|
|||
<Grid Grid.Row="1" |
|||
MinWidth="{StaticResource ToggleSwitchThemeMinWidth}" |
|||
HorizontalAlignment="Left" |
|||
VerticalAlignment="Top"> |
|||
|
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="{DynamicResource ToggleSwitchPreContentMargin}" /> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition Height="{DynamicResource ToggleSwitchPostContentMargin}" /> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition Width="Auto" /> |
|||
<ColumnDefinition Width="12" MaxWidth="12" /> |
|||
<ColumnDefinition Width="Auto" /> |
|||
</Grid.ColumnDefinitions> |
|||
|
|||
<Grid x:Name="SwitchAreaGrid" |
|||
Grid.RowSpan="3" |
|||
Grid.ColumnSpan="3" |
|||
TemplatedControl.IsTemplateFocusTarget="True" |
|||
Margin="0,5" /> |
|||
|
|||
<ContentPresenter x:Name="PART_OffContentPresenter" |
|||
Grid.RowSpan="3" |
|||
Grid.Column="2" |
|||
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="10" |
|||
BorderThickness="{DynamicResource ToggleSwitchOuterBorderStrokeThickness}" /> |
|||
|
|||
<Border x:Name="SwitchKnobBounds" |
|||
Grid.Row="1" |
|||
Height="20" |
|||
Width="40" |
|||
CornerRadius="10" |
|||
BorderThickness="{DynamicResource ToggleSwitchOnStrokeThickness}"/> |
|||
|
|||
<Canvas x:Name="SwitchKnob" Grid.Row="1" |
|||
HorizontalAlignment="Left" |
|||
Width="20" Height="20"> |
|||
|
|||
<Grid x:Name="MovingKnobs" |
|||
Width="20" Height="20"> |
|||
|
|||
<Ellipse x:Name="SwitchKnobOn" |
|||
Width="10" Height="10" /> |
|||
|
|||
<Ellipse x:Name="SwitchKnobOff" |
|||
Width="10" Height="10" /> |
|||
</Grid> |
|||
</Canvas> |
|||
</Grid> |
|||
</Grid> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
<!-- NormalState --> |
|||
<Style Selector="ToggleSwitch /template/ Grid#SwitchAreaGrid"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchContainerBackground}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Border#OuterBorder"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOff}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOff}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOn}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOn}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Ellipse#SwitchKnobOn"> |
|||
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOn}"/> |
|||
<Setter Property="Stroke" Value="{DynamicResource ToggleSwitchKnobStrokeOn}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Ellipse#SwitchKnobOff"> |
|||
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOff}"/> |
|||
<Setter Property="Stroke" Value="{DynamicResource ToggleSwitchKnobStrokeOff}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Grid#MovingKnobs"> |
|||
<Setter Property="Canvas.Left" Value="{DynamicResource KnobOffPosition}"/> |
|||
<Setter Property="Transitions"> |
|||
<Transitions> |
|||
<DoubleTransition Property="Canvas.Left" Duration="0:0:0.2" Easing="CubicEaseOut"/> |
|||
</Transitions> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
<!-- PointerOverState --> |
|||
<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> |
|||
|
|||
<Style Selector="ToggleSwitch:pointerover /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnPointerOver}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnPointerOver}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:pointerover /template/ Grid#SwitchAreaGrid"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchContainerBackgroundPointerOver}"/> |
|||
</Style> |
|||
|
|||
<!-- PressedState --> |
|||
<Style Selector="ToggleSwitch:pressed /template/ Border#OuterBorder"> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOffPressed}"/> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOffPressed}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:pressed /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnPressed}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnPressed}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:pressed /template/ Ellipse#SwitchKnobOff"> |
|||
<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> |
|||
|
|||
<!-- DisabledState --> |
|||
<Style Selector="ToggleSwitch:disabled"> |
|||
<Setter Property="Foreground" Value="{DynamicResource ToggleSwitchHeaderForegroundDisabled}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:disabled /template/ Border#OuterBorder"> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOffDisabled}"/> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOffPressed}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:disabled /template/ Ellipse#SwitchKnobOff"> |
|||
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOffDisabled}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:disabled /template/ Ellipse#SwitchKnobOn"> |
|||
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOnDisabled}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:disabled /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnDisabled}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnDisabled}"/> |
|||
</Style> |
|||
|
|||
<!-- CheckedState --> |
|||
<Style Selector="ToggleSwitch:checked /template/ Grid#MovingKnobs"> |
|||
<Setter Property="Canvas.Left" Value="{DynamicResource KnobOnPosition}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ Border#OuterBorder"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobOff"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobOn"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ ContentPresenter#PART_OffContentPresenter"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ ContentPresenter#PART_OnContentPresenter"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<!--UncheckedState --> |
|||
<Style Selector="ToggleSwitch:unchecked /template/ Grid#MovingKnobs"> |
|||
<Setter Property="Canvas.Left" Value="{DynamicResource KnobOffPosition}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ Border#OuterBorder"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ Ellipse#SwitchKnobOff"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ Ellipse#SwitchKnobOn"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ ContentPresenter#PART_OffContentPresenter"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ ContentPresenter#PART_OnContentPresenter"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
</Styles> |
|||
@ -0,0 +1,294 @@ |
|||
<Styles xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:sys="clr-namespace:System;assembly=netstandard"> |
|||
<Styles.Resources> |
|||
<Thickness x:Key="ToggleSwitchTopHeaderMargin">0,0,0,6</Thickness> |
|||
<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">20</x:Double> |
|||
<x:Double x:Key="KnobOffPosition">0</x:Double> |
|||
</Styles.Resources> |
|||
<Design.PreviewWith> |
|||
<StackPanel Margin="20" Width="250" Spacing="24" > |
|||
<StackPanel Spacing="12" > |
|||
<TextBlock |
|||
Text="Automatic updates" |
|||
Classes="h1"/> |
|||
<TextBlock |
|||
Text="Updates will be automaticly Downloaded and installed shile the computer is shutting down or restarting" |
|||
TextWrapping="Wrap"/> |
|||
<ToggleSwitch HorizontalContentAlignment="Left" |
|||
Content="Enable automatic Updates?" |
|||
OffContent="Uit" |
|||
OnContent="Aan" |
|||
VerticalAlignment="Bottom"/> |
|||
</StackPanel> |
|||
|
|||
<StackPanel Spacing="12"> |
|||
<TextBlock |
|||
Text="Previewer" |
|||
Classes="h1"/> |
|||
<TextBlock |
|||
Text="The previewer Shows a preview off your code, this could slow down your system" |
|||
TextWrapping="Wrap"/> |
|||
<ToggleSwitch |
|||
Content="Previewer" |
|||
IsChecked="True" /> |
|||
</StackPanel> |
|||
</StackPanel> |
|||
</Design.PreviewWith> |
|||
|
|||
<Style Selector="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="Template"> |
|||
<ControlTemplate> |
|||
<Grid Background="{TemplateBinding Background}" |
|||
RowDefinitions="Auto,*"> |
|||
|
|||
<ContentPresenter x:Name="PART_ContentPresenter" |
|||
Grid.Row="0" |
|||
Content="{TemplateBinding Content}" |
|||
ContentTemplate="{TemplateBinding ContentTemplate}" |
|||
Margin="{DynamicResource ToggleSwitchTopHeaderMargin}" |
|||
VerticalAlignment="Top"/> |
|||
|
|||
<Grid Grid.Row="1" |
|||
MinWidth="{StaticResource ToggleSwitchThemeMinWidth}" |
|||
HorizontalAlignment="Left" |
|||
VerticalAlignment="Top"> |
|||
|
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="{DynamicResource ToggleSwitchPreContentMargin}" /> |
|||
<RowDefinition Height="Auto" /> |
|||
<RowDefinition Height="{DynamicResource ToggleSwitchPostContentMargin}" /> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition Width="Auto" /> |
|||
<ColumnDefinition Width="12" MaxWidth="12" /> |
|||
<ColumnDefinition Width="Auto" /> |
|||
</Grid.ColumnDefinitions> |
|||
|
|||
<Grid x:Name="SwitchAreaGrid" |
|||
Grid.RowSpan="3" |
|||
Grid.ColumnSpan="3" |
|||
TemplatedControl.IsTemplateFocusTarget="True" |
|||
Margin="0,5" /> |
|||
|
|||
<ContentPresenter x:Name="PART_OffContentPresenter" |
|||
Grid.RowSpan="3" |
|||
Grid.Column="2" |
|||
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="10" |
|||
BorderThickness="{DynamicResource ToggleSwitchOuterBorderStrokeThickness}" /> |
|||
|
|||
<Border x:Name="SwitchKnobBounds" |
|||
Grid.Row="1" |
|||
Height="20" |
|||
Width="40" |
|||
CornerRadius="10" |
|||
BorderThickness="{DynamicResource ToggleSwitchOnStrokeThickness}"/> |
|||
|
|||
<Canvas x:Name="SwitchKnob" Grid.Row="1" |
|||
HorizontalAlignment="Left" |
|||
Width="20" Height="20"> |
|||
|
|||
<Grid x:Name="MovingKnobs" |
|||
Width="20" Height="20"> |
|||
|
|||
<Ellipse x:Name="SwitchKnobOn" |
|||
Width="10" Height="10" /> |
|||
|
|||
<Ellipse x:Name="SwitchKnobOff" |
|||
Width="10" Height="10" /> |
|||
</Grid> |
|||
</Canvas> |
|||
</Grid> |
|||
</Grid> |
|||
</ControlTemplate> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
<!-- NormalState --> |
|||
<Style Selector="ToggleSwitch /template/ Grid#SwitchAreaGrid"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchContainerBackground}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Border#OuterBorder"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOff}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOff}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOn}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOn}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Ellipse#SwitchKnobOn"> |
|||
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOn}"/> |
|||
<Setter Property="Stroke" Value="{DynamicResource ToggleSwitchKnobStrokeOn}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Ellipse#SwitchKnobOff"> |
|||
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOff}"/> |
|||
<Setter Property="Stroke" Value="{DynamicResource ToggleSwitchKnobStrokeOff}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch /template/ Grid#MovingKnobs"> |
|||
<Setter Property="Canvas.Left" Value="{DynamicResource KnobOffPosition}"/> |
|||
<Setter Property="Transitions"> |
|||
<Transitions> |
|||
<DoubleTransition Property="Canvas.Left" Duration="0:0:0.2" Easing="CubicEaseOut"/> |
|||
</Transitions> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
<!-- PointerOverState --> |
|||
<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> |
|||
|
|||
<Style Selector="ToggleSwitch:pointerover /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnPointerOver}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnPointerOver}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:pointerover /template/ Grid#SwitchAreaGrid"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchContainerBackgroundPointerOver}"/> |
|||
</Style> |
|||
|
|||
<!-- PressedState --> |
|||
<Style Selector="ToggleSwitch:pressed /template/ Border#OuterBorder"> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOffPressed}"/> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOffPressed}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:pressed /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnPressed}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnPressed}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:pressed /template/ Ellipse#SwitchKnobOff"> |
|||
<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> |
|||
|
|||
<!-- DisabledState --> |
|||
<Style Selector="ToggleSwitch:disabled"> |
|||
<Setter Property="Foreground" Value="{DynamicResource ToggleSwitchHeaderForegroundDisabled}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:disabled /template/ Border#OuterBorder"> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOffDisabled}"/> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOffPressed}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:disabled /template/ Ellipse#SwitchKnobOff"> |
|||
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOffDisabled}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:disabled /template/ Ellipse#SwitchKnobOn"> |
|||
<Setter Property="Fill" Value="{DynamicResource ToggleSwitchKnobFillOnDisabled}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:disabled /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Background" Value="{DynamicResource ToggleSwitchFillOnDisabled}"/> |
|||
<Setter Property="BorderBrush" Value="{DynamicResource ToggleSwitchStrokeOnDisabled}"/> |
|||
</Style> |
|||
|
|||
<!-- CheckedState --> |
|||
<Style Selector="ToggleSwitch:checked /template/ Grid#MovingKnobs"> |
|||
<Setter Property="Canvas.Left" Value="{DynamicResource KnobOnPosition}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ Border#OuterBorder"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobOff"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ Ellipse#SwitchKnobOn"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ ContentPresenter#PART_OffContentPresenter"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:checked /template/ ContentPresenter#PART_OnContentPresenter"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<!--UncheckedState --> |
|||
<Style Selector="ToggleSwitch:unchecked /template/ Grid#MovingKnobs"> |
|||
<Setter Property="Canvas.Left" Value="{DynamicResource KnobOffPosition}"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ Border#OuterBorder"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ Ellipse#SwitchKnobOff"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ Ellipse#SwitchKnobOn"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ Border#SwitchKnobBounds"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ ContentPresenter#PART_OffContentPresenter"> |
|||
<Setter Property="Opacity" Value="1"/> |
|||
</Style> |
|||
|
|||
<Style Selector="ToggleSwitch:unchecked /template/ ContentPresenter#PART_OnContentPresenter"> |
|||
<Setter Property="Opacity" Value="0"/> |
|||
</Style> |
|||
</Styles> |
|||
Loading…
Reference in new issue