From 8e10cd774ae47fd0828e0bbca99e844fabd4848b Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 4 Feb 2023 14:00:20 +0800 Subject: [PATCH 1/2] feat: Add new index for theme. fix some minor issue. --- demo/Semi.Avalonia.Demo.Desktop/App.axaml | 3 ++- demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs | 1 + demo/Semi.Avalonia.Demo/Pages/Overview.axaml | 6 ++++++ .../Semi.Avalonia.Demo/Pages/Overview.axaml.cs | 15 +++++++++++++++ src/Semi.Avalonia/Controls/RadioButton.axaml | 8 ++++---- src/Semi.Avalonia/Controls/ToggleSwitch.axaml | 2 +- src/Semi.Avalonia/Semi.Avalonia.csproj | 4 ++++ src/Semi.Avalonia/Themes/DarkTheme.axaml | 13 ++++++------- src/Semi.Avalonia/Themes/Index.axaml | 18 ++++++++++++++++++ 9 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 src/Semi.Avalonia/Themes/Index.axaml diff --git a/demo/Semi.Avalonia.Demo.Desktop/App.axaml b/demo/Semi.Avalonia.Demo.Desktop/App.axaml index 18e42be..3c2bebe 100644 --- a/demo/Semi.Avalonia.Demo.Desktop/App.axaml +++ b/demo/Semi.Avalonia.Demo.Desktop/App.axaml @@ -4,6 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Semi.Avalonia.Demo.Desktop"> - + + \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs b/demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs index d5fe94a..e70ba74 100644 --- a/demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs +++ b/demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Avalonia.Styling; using Semi.Avalonia.Demo.Views; namespace Semi.Avalonia.Demo.Desktop; diff --git a/demo/Semi.Avalonia.Demo/Pages/Overview.axaml b/demo/Semi.Avalonia.Demo/Pages/Overview.axaml index 5838836..5c909af 100644 --- a/demo/Semi.Avalonia.Demo/Pages/Overview.axaml +++ b/demo/Semi.Avalonia.Demo/Pages/Overview.axaml @@ -15,6 +15,12 @@ Text="Welcome to Semi Avalonia" Theme="{StaticResource TitleTextBlock}" /> + + diff --git a/demo/Semi.Avalonia.Demo/Pages/Overview.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/Overview.axaml.cs index b36a5b5..887944e 100644 --- a/demo/Semi.Avalonia.Demo/Pages/Overview.axaml.cs +++ b/demo/Semi.Avalonia.Demo/Pages/Overview.axaml.cs @@ -1,6 +1,8 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Interactivity; using Avalonia.Markup.Xaml; +using Avalonia.Styling; namespace Semi.Avalonia.Demo.Pages; @@ -10,4 +12,17 @@ public partial class Overview : UserControl { InitializeComponent(); } + + private void ToggleButton_OnIsCheckedChanged(object sender, RoutedEventArgs e) + { + var variant = Application.Current!.RequestedThemeVariant; + if (variant?.Key == "Dark") + { + Application.Current!.RequestedThemeVariant = ThemeVariant.Light; + } + else + { + Application.Current!.RequestedThemeVariant = ThemeVariant.Dark; + } + } } \ No newline at end of file diff --git a/src/Semi.Avalonia/Controls/RadioButton.axaml b/src/Semi.Avalonia/Controls/RadioButton.axaml index c7c0229..692813c 100644 --- a/src/Semi.Avalonia/Controls/RadioButton.axaml +++ b/src/Semi.Avalonia/Controls/RadioButton.axaml @@ -171,12 +171,12 @@ diff --git a/src/Semi.Avalonia/Controls/ToggleSwitch.axaml b/src/Semi.Avalonia/Controls/ToggleSwitch.axaml index b05fb51..062c8af 100644 --- a/src/Semi.Avalonia/Controls/ToggleSwitch.axaml +++ b/src/Semi.Avalonia/Controls/ToggleSwitch.axaml @@ -84,7 +84,7 @@ x:Name="PART_OffContentPresenter" Grid.Column="1" Margin="{DynamicResource ToggleSwitchOnContentMargin}" - HorizontalAlignment="Right" + HorizontalAlignment="Left" VerticalAlignment="Center" VerticalContentAlignment="Center" Content="{TemplateBinding OffContent}" diff --git a/src/Semi.Avalonia/Semi.Avalonia.csproj b/src/Semi.Avalonia/Semi.Avalonia.csproj index 892dfd1..5e6f80e 100644 --- a/src/Semi.Avalonia/Semi.Avalonia.csproj +++ b/src/Semi.Avalonia/Semi.Avalonia.csproj @@ -16,4 +16,8 @@ Please don't update if you are not using Avalonia latest nightly build. + + + + diff --git a/src/Semi.Avalonia/Themes/DarkTheme.axaml b/src/Semi.Avalonia/Themes/DarkTheme.axaml index b18c9c7..62739ee 100644 --- a/src/Semi.Avalonia/Themes/DarkTheme.axaml +++ b/src/Semi.Avalonia/Themes/DarkTheme.axaml @@ -1,16 +1,15 @@ - - + + - - - + + + diff --git a/src/Semi.Avalonia/Themes/Index.axaml b/src/Semi.Avalonia/Themes/Index.axaml new file mode 100644 index 0000000..b2c4605 --- /dev/null +++ b/src/Semi.Avalonia/Themes/Index.axaml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + From 5ba21de6bb30ddde9c60bbc94af1f507c90e007e Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 4 Feb 2023 14:15:19 +0800 Subject: [PATCH 2/2] feat: add ThemeVariant demo. --- .../Pages/ThemeVariantDemo.axaml | 14 +++++++++++--- .../Pages/ThemeVariantDemo.axaml.cs | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml index 77f5d88..7303773 100644 --- a/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml +++ b/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml @@ -7,7 +7,15 @@ d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> - - - + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml.cs index 7a177ae..92ea50b 100644 --- a/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml.cs +++ b/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml.cs @@ -1,13 +1,30 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Interactivity; using Avalonia.Markup.Xaml; +using Avalonia.Styling; namespace Semi.Avalonia.Demo.Pages; public partial class ThemeVariantDemo : UserControl { + private ThemeVariant _variant = ThemeVariant.Default; public ThemeVariantDemo() { InitializeComponent(); } + + private void Switch_OnIsCheckedChanged(object sender, RoutedEventArgs e) + { + if (_variant == ThemeVariant.Dark) + { + scope.RequestedThemeVariant = ThemeVariant.Default; + _variant = ThemeVariant.Default; + } + else + { + scope.RequestedThemeVariant = ThemeVariant.Dark; + _variant = ThemeVariant.Dark; + } + } } \ No newline at end of file