-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
298 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
Russkyc.UI.Avalonia.Gallery/Views/Pages/ToggleSwitchView.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<UserControl | ||
x:Class="Russkyc.UI.Avalonia.Gallery.Views.Pages.ToggleSwitchView" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
d:DesignWidth="800" | ||
mc:Ignorable="d"> | ||
<StackPanel Margin="24" Spacing="24"> | ||
<StackPanel Spacing="-2"> | ||
<TextBlock | ||
FontSize="24" | ||
FontWeight="Bold" | ||
Text="ToggleSwitch" /> | ||
<TextBlock Text="Displays a toggle switch." /> | ||
</StackPanel> | ||
<StackPanel Spacing="8"> | ||
<TextBlock | ||
FontSize="16" | ||
FontWeight="SemiBold" | ||
Text="ToggleSwitch Variants Preview" /> | ||
<Border Height="200" Classes="Card"> | ||
<WrapPanel | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
Orientation="Horizontal"> | ||
<WrapPanel.Styles> | ||
<Style Selector="ToggleSwitch"> | ||
<Setter Property="Margin" Value="4" /> | ||
</Style> | ||
</WrapPanel.Styles> | ||
<ToggleSwitch VerticalAlignment="Bottom" /> | ||
<ToggleSwitch | ||
VerticalAlignment="Bottom" | ||
OffContent="Off Content" | ||
OnContent="On Content" /> | ||
<ToggleSwitch | ||
VerticalAlignment="Bottom" | ||
IsEnabled="False" | ||
OffContent="Disabled" | ||
OnContent="Disabled" /> | ||
</WrapPanel> | ||
</Border> | ||
</StackPanel> | ||
<StackPanel Spacing="8"> | ||
<TextBlock | ||
FontSize="16" | ||
FontWeight="SemiBold" | ||
Text="Code" /> | ||
<ThemeVariantScope RequestedThemeVariant="Dark"> | ||
<TextBox | ||
Name="CodeBlock" | ||
Padding="12" | ||
CornerRadius="12" | ||
FontSize="16" | ||
IsReadOnly="True" /> | ||
</ThemeVariantScope> | ||
</StackPanel> | ||
</StackPanel> | ||
</UserControl> |
35 changes: 35 additions & 0 deletions
35
Russkyc.UI.Avalonia.Gallery/Views/Pages/ToggleSwitchView.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Avalonia.Controls; | ||
|
||
namespace Russkyc.UI.Avalonia.Gallery.Views.Pages; | ||
|
||
public partial class ToggleSwitchView : UserControl | ||
{ | ||
public ToggleSwitchView() | ||
{ | ||
InitializeComponent(); | ||
CodeBlock.Text = """ | ||
<Border Height="200" Classes="Card"> | ||
<WrapPanel | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
Orientation="Horizontal"> | ||
<WrapPanel.Styles> | ||
<Style Selector="ToggleSwitch"> | ||
<Setter Property="Margin" Value="4" /> | ||
</Style> | ||
</WrapPanel.Styles> | ||
<ToggleSwitch VerticalAlignment="Bottom" /> | ||
<ToggleSwitch | ||
VerticalAlignment="Bottom" | ||
OffContent="Off Content" | ||
OnContent="On Content" /> | ||
<ToggleSwitch | ||
VerticalAlignment="Bottom" | ||
IsEnabled="False" | ||
OffContent="Disabled" | ||
OnContent="Disabled" /> | ||
</WrapPanel> | ||
</Border> | ||
"""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
<Design.PreviewWith> | ||
<StackPanel | ||
Width="250" | ||
Margin="20" | ||
Spacing="24"> | ||
<StackPanel Orientation="Horizontal"> | ||
<ToggleSwitch VerticalAlignment="Bottom" /> | ||
<ToggleSwitch | ||
VerticalAlignment="Bottom" | ||
OffContent="Off Content" | ||
OnContent="On Content" /> | ||
<ToggleSwitch | ||
VerticalAlignment="Bottom" | ||
IsEnabled="False" | ||
OffContent="Disabled" | ||
OnContent="Disabled" /> | ||
</StackPanel> | ||
</StackPanel> | ||
</Design.PreviewWith> | ||
|
||
<Thickness x:Key="ToggleSwitchTopHeaderMargin">0,0,0,4</Thickness> | ||
<GridLength x:Key="ToggleSwitchPreContentMargin">0</GridLength> | ||
<GridLength x:Key="ToggleSwitchPostContentMargin">0</GridLength> | ||
<x:Double x:Key="ToggleSwitchThemeMinWidth">0</x:Double> | ||
|
||
<ControlTheme x:Key="{x:Type ToggleSwitch}" TargetType="ToggleSwitch"> | ||
<Setter Property="Foreground" Value="{DynamicResource Foreground}" /> | ||
<Setter Property="HorizontalAlignment" Value="Left" /> | ||
<Setter Property="VerticalAlignment" Value="Center" /> | ||
<Setter Property="HorizontalContentAlignment" Value="Left" /> | ||
<Setter Property="VerticalContentAlignment" Value="Center" /> | ||
<Setter Property="OffContent" Value="" /> | ||
<Setter Property="OnContent" Value="" /> | ||
<Setter Property="KnobTransitions"> | ||
<Transitions> | ||
<DoubleTransition | ||
Easing="CubicEaseOut" | ||
Property="Canvas.Left" | ||
Duration="0:0:0.2" /> | ||
</Transitions> | ||
</Setter> | ||
<Setter Property="Template"> | ||
<ControlTemplate> | ||
<Grid Background="{TemplateBinding Background}" RowDefinitions="Auto,*"> | ||
<ContentPresenter | ||
x:Name="PART_ContentPresenter" | ||
Grid.Row="0" | ||
Margin="{DynamicResource ToggleSwitchTopHeaderMargin}" | ||
VerticalAlignment="Top" | ||
Content="{TemplateBinding Content}" | ||
ContentTemplate="{TemplateBinding ContentTemplate}" | ||
RecognizesAccessKey="True" /> | ||
<Grid | ||
Grid.Row="1" | ||
MinWidth="{DynamicResource 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="8" MaxWidth="24" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
<Grid | ||
x:Name="SwitchAreaGrid" | ||
Grid.Row="0" | ||
Grid.RowSpan="3" | ||
Grid.Column="0" | ||
Grid.ColumnSpan="3" | ||
TemplatedControl.IsTemplateFocusTarget="True" /> | ||
<ContentPresenter | ||
x:Name="PART_OffContentPresenter" | ||
Grid.Row="0" | ||
Grid.RowSpan="3" | ||
Grid.Column="2" | ||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" | ||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" | ||
Content="{TemplateBinding OffContent}" | ||
ContentTemplate="{TemplateBinding OffContentTemplate}" /> | ||
<ContentPresenter | ||
x:Name="PART_OnContentPresenter" | ||
Grid.Row="0" | ||
Grid.RowSpan="3" | ||
Grid.Column="2" | ||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" | ||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" | ||
Content="{TemplateBinding OnContent}" | ||
ContentTemplate="{TemplateBinding OnContentTemplate}" /> | ||
<Border | ||
x:Name="OuterBorder" | ||
Grid.Row="1" | ||
Grid.Column="0" | ||
Width="40" | ||
Height="26" | ||
Background="{DynamicResource BorderBrush}" | ||
BorderBrush="{DynamicResource BorderBrush}" | ||
BorderThickness="0" | ||
CornerRadius="14" /> | ||
<Border | ||
x:Name="SwitchKnobBounds" | ||
Grid.Row="1" | ||
Grid.Column="0" | ||
Width="39" | ||
Height="26" | ||
Background="{DynamicResource PrimaryBrush}" | ||
BorderBrush="{DynamicResource BorderBrush}" | ||
BorderThickness="0" | ||
CornerRadius="14" /> | ||
<Canvas | ||
x:Name="PART_SwitchKnob" | ||
Grid.Row="1" | ||
Grid.Column="0" | ||
Width="13" | ||
Height="20" | ||
HorizontalAlignment="Left"> | ||
<Grid | ||
x:Name="PART_MovingKnobs" | ||
Width="26" | ||
Height="20"> | ||
<Ellipse | ||
x:Name="SwitchKnobOn" | ||
Width="18" | ||
Height="18" | ||
VerticalAlignment="Center" | ||
Fill="{DynamicResource BackgroundBrush}" /> | ||
<Ellipse | ||
x:Name="SwitchKnobOff" | ||
Width="18" | ||
Height="18" | ||
VerticalAlignment="Center" | ||
Fill="{DynamicResource BackgroundBrush}" /> | ||
</Grid> | ||
</Canvas> | ||
</Grid> | ||
</Grid> | ||
</ControlTemplate> | ||
</Setter> | ||
|
||
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter:empty"> | ||
<Setter Property="Margin" Value="0" /> | ||
</Style> | ||
<!-- DisabledState --> | ||
<Style Selector="^:disabled"> | ||
<Setter Property="Foreground" Value="{DynamicResource MutedForegroundBrush}" /> | ||
<Style Selector="^ /template/ Border#OuterBorder"> | ||
<Setter Property="Background" Value="{DynamicResource MutedForegroundBrush}" /> | ||
</Style> | ||
</Style> | ||
<!-- CheckedState --> | ||
<Style Selector="^:checked"> | ||
<Style Selector="^ /template/ Ellipse#SwitchKnobOff"> | ||
<Setter Property="Opacity" Value="0" /> | ||
</Style> | ||
<Style Selector="^ /template/ Ellipse#SwitchKnobOn"> | ||
<Setter Property="Opacity" Value="1" /> | ||
</Style> | ||
<Style Selector="^ /template/ ContentPresenter#PART_OffContentPresenter"> | ||
<Setter Property="Opacity" Value="0" /> | ||
</Style> | ||
<Style Selector="^ /template/ ContentPresenter#PART_OnContentPresenter"> | ||
<Setter Property="Opacity" Value="1" /> | ||
</Style> | ||
</Style> | ||
<!-- UncheckedState --> | ||
<Style Selector="^:unchecked"> | ||
<Style Selector="^ /template/ Ellipse#SwitchKnobOff"> | ||
<Setter Property="Opacity" Value="1" /> | ||
</Style> | ||
<Style Selector="^ /template/ Ellipse#SwitchKnobOn"> | ||
<Setter Property="Opacity" Value="0" /> | ||
</Style> | ||
<Style Selector="^ /template/ Border#SwitchKnobBounds"> | ||
<Setter Property="Opacity" Value="0" /> | ||
</Style> | ||
<Style Selector="^ /template/ ContentPresenter#PART_OffContentPresenter"> | ||
<Setter Property="Opacity" Value="1" /> | ||
</Style> | ||
<Style Selector="^ /template/ ContentPresenter#PART_OnContentPresenter"> | ||
<Setter Property="Opacity" Value="0" /> | ||
</Style> | ||
</Style> | ||
</ControlTheme> | ||
</ResourceDictionary> |