feat: Add ToggleSwitch theme and demos.

This commit is contained in:
NaBian committed 2026-06-14 00:18:33 +08:00
1 parent b36b3b4ed8
commit d32f4b66c0
8 files changed
+291 -69

No files matched your search

@@ -8,6 +8,7 @@
[ "Button", "ButtonDemo", "Brush.ButtonClick", "", "" ],
[ "RepeatButton", "RepeatButtonDemo", "Brush.RepeatButton", "", "" ],
[ "ToggleButton", "ToggleButtonDemo", "Brush.Toggle", "", "" ],
[ "ToggleSwitch", "ToggleSwitchDemo", "Brush.Toggle", "1", "" ],
[ "RadioButton", "RadioButtonDemo", "Brush.RadioButton", "", "" ],
[ "HyperlinkButton", "HyperlinkButtonDemo", "Brush.Hyperlink", "", "" ],
[ "CheckBox", "CheckBoxDemo", "Brush.CheckBoxChecked", "", "" ],
@@ -34,83 +35,17 @@
"selectedIndex": 0,
"group": true,
"demoItemList": [
[ "FloatingBlock", "FloatingBlockDemo", "Brush.LikeFilled", "", "Interacting" ],
[ "ConfettiCannon", "ConfettiCannonDemo", "Brush.Favorite", "", "Interacting" ],
[ "PropertyGrid", "PropertyGridDemo", "Brush.PropertyGridEditorPart", "", "DataEntry" ],
[ "ImageSelector", "ImageSelectorDemo", "Brush.Image", "", "DataEntry" ],
[ "ImageBlock", "ImageBlockDemo", "Brush.ImageStack", "", "DataDisplay" ],
[ "Magnifier", "MagnifierDemo", "Brush.Search", "", "Interacting" ],
[ "Gravatar", "GravatarDemo", "Brush.User", "", "DataDisplay" ],
[ "Badge", "BadgeDemo", "Brush.CheckDot", "", "DataDisplay" ],
[ "SplitButton", "SplitButtonDemo", "Brush.SplitButton", "", "Button" ],
[ "ButtonGroup", "ButtonGroupDemo", "Brush.ButtonGroup", "", "Button" ],
[ "ProgressButton", "ProgressButtonDemo", "Brush.ProgressBarStatusBar8", "", "Button" ],
[ "Poptip", "PoptipDemo", "Brush.ToolTip", "", "DataDisplay" ],
[ "CheckComboBox", "CheckComboBoxDemo", "Brush.CheckBoxList", "", "DataEntry" ],
[ "AutoCompleteTextBox", "AutoCompleteTextBoxDemo", "Brush.AutoComplete", "1", "DataEntry" ],
[ "PinBox", "PinBoxDemo", "Brush.Ellipsis", "", "DataEntry" ],
[ "Clock", "ClockDemo", "Brush.Time", "", "DataEntry" ],
[ "TimePicker", "TimePickerDemo", "Brush.TimePicker", "", "DataEntry" ],
[ "CalendarWithClock", "CalendarWithClockDemo", "Brush.Calendar", "", "DataEntry" ],
[ "DateTimePicker", "DateTimePickerDemo", "Brush.DateTimePicker", "", "DataEntry" ],
[ "Transfer", "TransferDemo", "Brush.SyncArrow", "", "DataEntry" ],
[ "FlipClock", "FlipClockDemo", "Brush.FlipVertical", "", "DataDisplay" ],
[ "Rate", "RateDemo", "Brush.HeartFilled", "", "DataEntry" ],
[ "Shield", "ShieldDemo", "Brush.SplitKeyValuePair", "", "DataDisplay" ],
[ "SearchBar", "SearchBarDemo", "Brush.Search", "", "DataEntry" ],
[ "Tag", "TagDemo", "Brush.Tag", "", "DataDisplay" ],
[ "GifImage", "GifImageDemo", "Brush.Animation", "", "DataDisplay" ],
[ "OutlineText", "OutlineTextDemo", "Brush.TextBlock", "", "DataDisplay" ],
[ "RunningBlock", "RunningBlockDemo", "Brush.Dynamic", "", "DataDisplay" ],
[ "Card", "CardDemo", "Brush.ContactCard", "", "DataDisplay" ],
[ "ElementGroup", "ElementGroupDemo", "Brush.ButtonGroup", "1", "Layout" ],
[ "Divider", "DividerDemo", "Brush.DottedSplitter", "", "Layout" ],
[ "CirclePanel", "CirclePanelDemo", "Brush.ColorWheel", "", "Layout" ],
[ "Grid", "GridDemo", "Brush.GridPane", "", "Layout" ],
[ "FlexPanel", "FlexPanelDemo", "Brush.FlowLayoutPanel", "1", "Layout" ],
[ "UniformSpacingPanel", "UniformSpacingPanelDemo", "Brush.IncreaseHorizontalSpacing", "1", "Layout" ],
[ "RelativePanel", "RelativePanelDemo", "Brush.TransformRelative", "", "Layout" ],
[ "WaterfallPanel", "WaterfallPanelDemo", "Brush.Panel", "", "Layout" ],
[ "HoneycombPanel", "HoneycombPanelDemo", "Brush.PolygonHexagon", "", "Layout" ],
[ "TransitioningContentControl", "TransitioningContentControlDemo", "Brush.TransitioningContentControl", "", "Interacting" ],
[ "Drawer", "DrawerDemo", "Brush.TransactedReceiveScope", "", "Feedback" ],
[ "CoverView", "CoverViewDemo", "Brush.DetailDataView", "", "DataDisplay" ],
[ "CoverFlow", "CoverFlowDemo", "Brush.LinearCarousel", "", "DataDisplay" ],
[ "ProgressBar", "ProgressBarDemo", "Brush.ProgressBar", "", "Feedback" ],
[ "StepBar", "StepBarDemo", "Brush.Flow", "", "Navigation" ],
[ "Growl", "GrowlDemo", "Brush.Message", "", "Feedback" ],
[ "Loading", "LoadingDemo", "Brush.Loading", "", "Feedback" ],
[ "ColorPicker", "ColorPickerDemo", "Brush.ColorPalette", "", "DataEntry" ],
[ "Carousel", "CarouselDemo", "Brush.Carousel", "", "DataDisplay" ],
[ "CompareSlider", "CompareSliderDemo", "Brush.SplitterControl", "", "Interacting" ],
[ "PreviewSlider", "PreviewSliderDemo", "Brush.HoverMenu", "", "DataEntry" ],
[ "RangeSlider", "RangeSliderDemo", "Brush.Indexer", "", "DataEntry" ],
[ "TimeBar", "TimeBarDemo", "Brush.Timeline", "", "DataEntry" ],
[ "Pagination", "PaginationDemo", "Brush.Paginator", "", "Navigation" ],
[ "TabControl", "TabControlDemo", "Brush.TabPage", "", "DataDisplay" ],
[ "SideMenu", "SideMenuDemo", "Brush.MainMenuControl", "", "Navigation" ],
[ "Notification", "NotificationDemo", "Brush.Procedure", "", "Feedback" ],
[ "Dialog", "DialogDemo", "Brush.Dialog", "", "Feedback" ],
[ "Screenshot", "ScreenshotDemo", "Brush.WindowScreenshot", "", "" ],
[ "GotoTop", "GotoTopDemo", "Brush.GoToTop", "", "" ],
[ "ChatBubble", "ChatBubbleDemo", "Brush.FeedbackBubble", "", "" ],
[ "Watermark", "WatermarkDemo", "Brush.GridLight", "1", "" ],
[ "NotifyIcon", "NotifyIconDemo", "Brush.NotificationHub", "", "" ],
[ "ImageBrowser", "ImageBrowserDemo", "Brush.ImageBrowser", "", "" ],
[ "AnimationPath", "AnimationPathDemo", "Brush.Path", "", "" ],
[ "ScrollViewer", "ScrollViewerDemo", "Brush.ScrollBox", "", "" ],
[ "Sprite", "SpriteDemo", "Brush.HandyControl", "", "" ],
[ "Window", "WindowDemo", "Brush.WindowsForm", "", "" ]
]
},
{
"title": "Tools",
"selectedIndex": 0,
"group": false,
"demoItemList": [
[ "HatchBrushGenerator", "HatchBrushGeneratorDemo", "Brush.DataGenerator", "", "" ],
[ "MorphingAnimation", "GeometryAnimationDemo", "Brush.Animation", "", "" ],
[ "Effects", "EffectsDemo", "Brush.Effects", "", "" ]
[ "UniformSpacingPanel", "UniformSpacingPanelDemo", "Brush.IncreaseHorizontalSpacing", "1", "Layout" ]
]
}
]
@@ -0,0 +1,40 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
x:Class="HandyControlDemo.UserControl.UniformSpacingPanelDemo"
Background="{DynamicResource RegionBrush}">
<TransitioningContentControl>
<ScrollViewer>
<StackPanel Margin="32" Spacing="10">
<hc:UniformSpacingPanel Spacing="10">
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
</hc:UniformSpacingPanel>
<Separator/>
<hc:UniformSpacingPanel Spacing="10" Orientation="Vertical">
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
</hc:UniformSpacingPanel>
<Separator/>
<hc:UniformSpacingPanel Spacing="10" Width="300" ChildWrapping="Wrap" HorizontalAlignment="Left">
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
</hc:UniformSpacingPanel>
<Separator/>
<hc:UniformSpacingPanel Spacing="10" Orientation="Vertical" Height="70" ChildWrapping="Wrap" HorizontalAlignment="Left">
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
<Button Content="{x:Static langs:Lang.ContentDemoStr}"/>
</hc:UniformSpacingPanel>
</StackPanel>
</ScrollViewer>
</TransitioningContentControl>
</UserControl>
@@ -0,0 +1,9 @@
namespace HandyControlDemo.UserControl;
public partial class UniformSpacingPanelDemo : Avalonia.Controls.UserControl
{
public UniformSpacingPanelDemo()
{
InitializeComponent();
}
}
@@ -1,4 +1,4 @@
<UserControl x:Class="HandyControlDemo.UserControl.LeftMainContent"
<UserControl x:Class="HandyControlDemo.UserControl.LeftMainContent"
Background="{DynamicResource RegionBrush}"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -34,11 +34,13 @@
ItemsSource="{Binding DemoItemList}">
<ListBox.ItemTemplate>
<DataTemplate DataType="data:DemoItemModel">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Rectangle Width="16"
Height="16"
VerticalAlignment="Center"
Fill="{Binding ImageBrush}" />
<TextBlock Margin="6,0,0,0"
VerticalAlignment="Center"
Text="{Binding Name}" />
<Path IsVisible="{Binding IsNew}"
VerticalAlignment="Center"
@@ -0,0 +1,56 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
x:Class="HandyControlDemo.UserControl.ToggleSwitchDemo"
Background="{DynamicResource RegionBrush}">
<TransitioningContentControl>
<ScrollViewer>
<StackPanel Margin="32" Spacing="20">
<TextBlock Text="Default" Theme="{StaticResource TextBlockLargeBold}" />
<WrapPanel>
<StackPanel VerticalAlignment="Center" Margin="10">
<ToggleSwitch IsChecked="True" Margin="5" HorizontalAlignment="Center" />
<ToggleSwitch Margin="5" HorizontalAlignment="Center" />
<ToggleSwitch IsEnabled="False" IsChecked="True" Margin="5" HorizontalAlignment="Center" />
<ToggleSwitch IsEnabled="False" Margin="5" HorizontalAlignment="Center" />
</StackPanel>
<StackPanel VerticalAlignment="Center" Margin="10">
<ToggleSwitch IsChecked="True" Margin="5" HorizontalAlignment="Center"
hc:VisualElement.HighlightBrush="{DynamicResource DangerBrush}" />
<ToggleSwitch IsChecked="True" Margin="5" HorizontalAlignment="Center"
hc:VisualElement.HighlightBrush="{DynamicResource SuccessBrush}" />
<ToggleSwitch IsChecked="True" Margin="5" HorizontalAlignment="Center"
hc:VisualElement.HighlightBrush="{DynamicResource WarningBrush}" />
<ToggleSwitch IsChecked="True" Margin="5" HorizontalAlignment="Center"
hc:VisualElement.HighlightBrush="{DynamicResource InfoBrush}" />
</StackPanel>
<StackPanel VerticalAlignment="Center" Margin="10">
<ToggleSwitch hc:ToggleButtonAttach.ShowLabel="True" IsChecked="True" Margin="5" HorizontalAlignment="Center" />
<ToggleSwitch hc:ToggleButtonAttach.ShowLabel="True" Margin="5" HorizontalAlignment="Center" />
</StackPanel>
<StackPanel VerticalAlignment="Center" Margin="10">
<ToggleSwitch IsChecked="True" Margin="5" HorizontalAlignment="Left"
OnContent="On" OffContent="Off" />
<ToggleSwitch Margin="5" HorizontalAlignment="Left"
OnContent="On" OffContent="Off" />
</StackPanel>
</WrapPanel>
<Separator />
<TextBlock Text="Small" Theme="{StaticResource TextBlockLargeBold}" />
<WrapPanel>
<StackPanel VerticalAlignment="Center" Margin="10">
<ToggleSwitch Theme="{StaticResource ToggleSwitch.Small}" IsChecked="True" Margin="5,8" HorizontalAlignment="Center" />
<ToggleSwitch Theme="{StaticResource ToggleSwitch.Small}" Margin="5,8" HorizontalAlignment="Center" />
<ToggleSwitch Theme="{StaticResource ToggleSwitch.Small}" IsEnabled="False" IsChecked="True" Margin="5,8" HorizontalAlignment="Center" />
</StackPanel>
<StackPanel VerticalAlignment="Center" Margin="10">
<ToggleSwitch Theme="{StaticResource ToggleSwitch.Small}" hc:ToggleButtonAttach.ShowLabel="True" IsChecked="True" Margin="5,8" HorizontalAlignment="Center" />
<ToggleSwitch Theme="{StaticResource ToggleSwitch.Small}" hc:ToggleButtonAttach.ShowLabel="True" Margin="5,8" HorizontalAlignment="Center" />
</StackPanel>
</WrapPanel>
</StackPanel>
</ScrollViewer>
</TransitioningContentControl>
</UserControl>
@@ -0,0 +1,9 @@
namespace HandyControlDemo.UserControl;
public partial class ToggleSwitchDemo : Avalonia.Controls.UserControl
{
public ToggleSwitchDemo()
{
InitializeComponent();
}
}
@@ -35,6 +35,7 @@
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/HyperlinkButton.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/RepeatButton.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ToggleButton.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/ToggleSwitch.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/RadioButton.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/CheckBox.axaml" />
<MergeResourceInclude Source="avares://HandyControl/Themes/Styles/Border.axaml" />
@@ -0,0 +1,170 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:ClassModifier="internal"
xmlns:hc="clr-namespace:HandyControl.Controls">
<ControlTheme x:Key="ToggleSwitchBaseStyle"
TargetType="ToggleSwitch">
<Setter Property="hc:VisualElement.HighlightBrush"
Value="{DynamicResource PrimaryBrush}" />
<Setter Property="hc:VisualElement.HighlightForeground"
Value="{DynamicResource SecondaryBorderBrush}" />
<Setter Property="Background"
Value="{DynamicResource SecondaryRegionBrush}" />
<Setter Property="Foreground"
Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="BorderBrush"
Value="{DynamicResource BorderBrush}" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Padding"
Value="6,0,0,0" />
<Setter Property="Height"
Value="24" />
<Setter Property="ClipToBounds"
Value="False" />
<Setter Property="Template">
<ControlTemplate TargetType="ToggleSwitch">
<Grid Background="Transparent"
ColumnDefinitions="Auto, *">
<Viewbox ClipToBounds="False">
<Panel Width="80"
Height="48">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
CornerRadius="24"
x:Name="innerBorder">
<Ellipse HorizontalAlignment="Right"
IsVisible="{TemplateBinding hc:ToggleButtonAttach.ShowLabel}"
Margin="0 0 12 0"
Width="16"
Height="16"
StrokeThickness="2"
Stroke="{TemplateBinding hc:VisualElement.HighlightForeground}" />
<Border.Transitions>
<Transitions>
<DoubleTransition Property="Opacity"
Duration="0:0:0.2" />
</Transitions>
</Border.Transitions>
</Border>
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Opacity="0"
Background="{TemplateBinding hc:VisualElement.HighlightBrush}"
CornerRadius="24"
x:Name="lightBorder">
<Rectangle HorizontalAlignment="Left"
IsVisible="{TemplateBinding hc:ToggleButtonAttach.ShowLabel}"
Margin="18 0 0 0"
Width="2"
Height="16"
RadiusX="1"
RadiusY="1"
Fill="{DynamicResource TextIconBrush}" />
<Border.Transitions>
<Transitions>
<DoubleTransition Property="Opacity"
Duration="0:0:0.2" />
</Transitions>
</Border.Transitions>
</Border>
<Panel x:Name="PART_MovingKnobs"
HorizontalAlignment="Left"
RenderTransform="translateX(0px)">
<Panel.Transitions>
<Transitions>
<TransformOperationsTransition Property="RenderTransform"
Easing="CubicEaseInOut"
Duration="0:0:0.2" />
</Transitions>
</Panel.Transitions>
<Border Margin="2"
x:Name="SwitchKnobBorder"
CornerRadius="22"
Effect="{StaticResource EffectShadow2}"
Background="White"
Width="44"
Height="44">
<Panel x:Name="PART_SwitchKnob" />
</Border>
</Panel>
</Panel>
</Viewbox>
<Panel Grid.Column="1"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
<ContentPresenter x:Name="PART_OffContentPresenter"
Focusable="False"
Content="{TemplateBinding OffContent}"
ContentTemplate="{TemplateBinding OffContentTemplate}"
IsVisible="False" />
<ContentPresenter x:Name="PART_OnContentPresenter"
Focusable="False"
Content="{TemplateBinding OnContent}"
ContentTemplate="{TemplateBinding OnContentTemplate}"
IsVisible="False" />
</Panel>
</Grid>
</ControlTemplate>
</Setter>
<Style Selector="^:checked">
<Style Selector="^ /template/ Panel#PART_MovingKnobs">
<Setter Property="RenderTransform"
Value="translateX(32px)" />
</Style>
<Style Selector="^ /template/ Border#lightBorder">
<Setter Property="Opacity"
Value="1" />
</Style>
<Style Selector="^ /template/ Border#innerBorder">
<Setter Property="Opacity"
Value="0" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_OnContentPresenter">
<Setter Property="IsVisible"
Value="True" />
</Style>
</Style>
<Style Selector="^:unchecked">
<Style Selector="^ /template/ Panel#PART_MovingKnobs">
<Setter Property="RenderTransform"
Value="translateX(0px)" />
</Style>
<Style Selector="^ /template/ Border#lightBorder">
<Setter Property="Opacity"
Value="0" />
</Style>
<Style Selector="^ /template/ Border#innerBorder">
<Setter Property="Opacity"
Value="1" />
</Style>
<Style Selector="^ /template/ ContentPresenter#PART_OffContentPresenter">
<Setter Property="IsVisible"
Value="True" />
</Style>
</Style>
<Style Selector="^:disabled">
<Setter Property="Opacity"
Value="0.4" />
</Style>
</ControlTheme>
<ControlTheme x:Key="{x:Type ToggleSwitch}"
BasedOn="{StaticResource ToggleSwitchBaseStyle}"
TargetType="ToggleSwitch" />
<ControlTheme x:Key="ToggleSwitch.Small"
BasedOn="{StaticResource ToggleSwitchBaseStyle}"
TargetType="ToggleSwitch">
<Setter Property="Height"
Value="16" />
</ControlTheme>
</ResourceDictionary>