From 67f33125f61917f877d3e0173a651d82f9a367c7 Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Sun, 22 Dec 2024 14:04:10 +0800
Subject: [PATCH 1/5] feat: redesign ThemeVariantDemo.
---
.../Pages/ThemeVariantDemo.axaml | 28 +++++++++++++++----
.../Pages/ThemeVariantDemo.axaml.cs | 25 ++++++++++++-----
2 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml
index 7303773..6f5bcf9 100644
--- a/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml
+++ b/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml
@@ -4,18 +4,36 @@
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"
+ xmlns:vm="clr-namespace:Semi.Avalonia.Demo.Pages"
+ x:DataType="vm:ThemeVariantDemoViewModel"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml.cs
index 2d80dd9..ad7366f 100644
--- a/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml.cs
+++ b/demo/Semi.Avalonia.Demo/Pages/ThemeVariantDemo.axaml.cs
@@ -1,8 +1,7 @@
-using Avalonia;
+using System.Collections.Generic;
using Avalonia.Controls;
-using Avalonia.Interactivity;
-using Avalonia.Markup.Xaml;
using Avalonia.Styling;
+using CommunityToolkit.Mvvm.ComponentModel;
namespace Semi.Avalonia.Demo.Pages;
@@ -11,10 +10,22 @@ public partial class ThemeVariantDemo : UserControl
public ThemeVariantDemo()
{
InitializeComponent();
+ this.DataContext = new ThemeVariantDemoViewModel();
}
+}
- private void Switch_OnIsCheckedChanged(object sender, RoutedEventArgs e)
- {
- scope.RequestedThemeVariant = scope.ActualThemeVariant == ThemeVariant.Dark ? ThemeVariant.Light : ThemeVariant.Dark;
- }
+public partial class ThemeVariantDemoViewModel : ObservableObject
+{
+ [ObservableProperty] private ThemeVariant? _selectedThemeVariant;
+
+ public IEnumerable ThemeVariants =>
+ [
+ ThemeVariant.Default,
+ ThemeVariant.Light,
+ ThemeVariant.Dark,
+ SemiTheme.Aquatic,
+ SemiTheme.Desert,
+ SemiTheme.Dust,
+ SemiTheme.NightSky,
+ ];
}
\ No newline at end of file
From 691e9987bcf532e478b8abb629e3ef728931a0d6 Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Sun, 22 Dec 2024 14:04:35 +0800
Subject: [PATCH 2/5] feat: add High-contrast theme doc.
---
.../Pages/HighContrastTheme.axaml | 108 ++++++++++++++++++
.../Pages/HighContrastTheme.axaml.cs | 28 +++++
demo/Semi.Avalonia.Demo/Views/MainView.axaml | 3 +
3 files changed, 139 insertions(+)
create mode 100644 demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml
create mode 100644 demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml.cs
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml b/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml
new file mode 100644
index 0000000..01b2d1b
--- /dev/null
+++ b/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml
@@ -0,0 +1,108 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml.cs
new file mode 100644
index 0000000..1146f5c
--- /dev/null
+++ b/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml.cs
@@ -0,0 +1,28 @@
+using System.Collections.Generic;
+using Avalonia.Controls;
+using Avalonia.Styling;
+using CommunityToolkit.Mvvm.ComponentModel;
+
+namespace Semi.Avalonia.Demo.Pages;
+
+public partial class HighContrastTheme : UserControl
+{
+ public HighContrastTheme()
+ {
+ InitializeComponent();
+ this.DataContext = new HighContrastThemeViewModel();
+ }
+}
+
+public partial class HighContrastThemeViewModel : ObservableObject
+{
+ [ObservableProperty] private ThemeVariant? _selectedThemeVariant = SemiTheme.Aquatic;
+
+ public IEnumerable ThemeVariants =>
+ [
+ SemiTheme.Aquatic,
+ SemiTheme.Desert,
+ SemiTheme.Dust,
+ SemiTheme.NightSky,
+ ];
+}
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Views/MainView.axaml b/demo/Semi.Avalonia.Demo/Views/MainView.axaml
index 376aee0..ce949a5 100644
--- a/demo/Semi.Avalonia.Demo/Views/MainView.axaml
+++ b/demo/Semi.Avalonia.Demo/Views/MainView.axaml
@@ -109,6 +109,9 @@
+
+
+
From 50c3b7cf0b6e7d7fac893944a91bffb45e8764ae Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Sun, 22 Dec 2024 15:50:47 +0800
Subject: [PATCH 3/5] feat: add preview options.
---
.../Pages/HighContrastTheme.axaml | 98 ++++++++++++++++++-
1 file changed, 94 insertions(+), 4 deletions(-)
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml b/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml
index 01b2d1b..f22d4a1 100644
--- a/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml
+++ b/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml
@@ -3,18 +3,108 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Semi.Avalonia.Demo.Pages"
- mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1450"
x:DataType="vm:HighContrastThemeViewModel"
x:Class="Semi.Avalonia.Demo.Pages.HighContrastTheme">
-
+
+
+ SelectedItem="{Binding SelectedThemeVariant}">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 25aa8fa3f20aef48fb71fc4e93c3c20e5ee4dade Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Mon, 23 Dec 2024 01:37:49 +0800
Subject: [PATCH 4/5] feat: add DataGrid description.
---
...rastTheme.axaml => HighContrastDemo.axaml} | 61 ++++++++-
.../Pages/HighContrastDemo.axaml.cs | 13 ++
.../Pages/HighContrastTheme.axaml.cs | 28 ----
.../ViewModels/HighContrastDemoViewModel.cs | 122 ++++++++++++++++++
demo/Semi.Avalonia.Demo/Views/MainView.axaml | 2 +-
5 files changed, 193 insertions(+), 33 deletions(-)
rename demo/Semi.Avalonia.Demo/Pages/{HighContrastTheme.axaml => HighContrastDemo.axaml} (81%)
create mode 100644 demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml.cs
delete mode 100644 demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml.cs
create mode 100644 demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
similarity index 81%
rename from demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml
rename to demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
index f22d4a1..630b0b8 100644
--- a/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml
+++ b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
@@ -2,12 +2,12 @@
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"
- xmlns:vm="clr-namespace:Semi.Avalonia.Demo.Pages"
+ xmlns:vm="clr-namespace:Semi.Avalonia.Demo.ViewModels"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1450"
- x:DataType="vm:HighContrastThemeViewModel"
- x:Class="Semi.Avalonia.Demo.Pages.HighContrastTheme">
+ x:DataType="vm:HighContrastDemoViewModel"
+ x:Class="Semi.Avalonia.Demo.Pages.HighContrastDemo">
-
+
@@ -193,6 +193,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml.cs
new file mode 100644
index 0000000..e8f4350
--- /dev/null
+++ b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml.cs
@@ -0,0 +1,13 @@
+using Avalonia.Controls;
+using Semi.Avalonia.Demo.ViewModels;
+
+namespace Semi.Avalonia.Demo.Pages;
+
+public partial class HighContrastDemo : UserControl
+{
+ public HighContrastDemo()
+ {
+ InitializeComponent();
+ this.DataContext = new HighContrastDemoViewModel();
+ }
+}
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml.cs
deleted file mode 100644
index 1146f5c..0000000
--- a/demo/Semi.Avalonia.Demo/Pages/HighContrastTheme.axaml.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System.Collections.Generic;
-using Avalonia.Controls;
-using Avalonia.Styling;
-using CommunityToolkit.Mvvm.ComponentModel;
-
-namespace Semi.Avalonia.Demo.Pages;
-
-public partial class HighContrastTheme : UserControl
-{
- public HighContrastTheme()
- {
- InitializeComponent();
- this.DataContext = new HighContrastThemeViewModel();
- }
-}
-
-public partial class HighContrastThemeViewModel : ObservableObject
-{
- [ObservableProperty] private ThemeVariant? _selectedThemeVariant = SemiTheme.Aquatic;
-
- public IEnumerable ThemeVariants =>
- [
- SemiTheme.Aquatic,
- SemiTheme.Desert,
- SemiTheme.Dust,
- SemiTheme.NightSky,
- ];
-}
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs
new file mode 100644
index 0000000..df80437
--- /dev/null
+++ b/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs
@@ -0,0 +1,122 @@
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.ApplicationLifetimes;
+using Avalonia.Media;
+using Avalonia.Styling;
+using CommunityToolkit.Mvvm.ComponentModel;
+
+namespace Semi.Avalonia.Demo.ViewModels;
+
+public partial class HighContrastDemoViewModel : ObservableObject
+{
+ [ObservableProperty] private ThemeVariant? _selectedThemeVariant;
+ public IEnumerable ThemeVariants { get; }
+ public ObservableCollection ColorResources { get; set; }
+
+ public HighContrastDemoViewModel()
+ {
+ ThemeVariants =
+ [
+ SemiTheme.Aquatic,
+ SemiTheme.Desert,
+ SemiTheme.Dust,
+ SemiTheme.NightSky,
+ ];
+ ColorResources =
+ [
+ new ColorResource
+ {
+ ResourceKey = "WindowColor",
+ Brush = new SolidColorBrush(Color.Parse("#202020")),
+ Description = "Background of pages, panes, popups, and windows.",
+ PairWith = "WindowTextColor"
+ },
+ new ColorResource
+ {
+ ResourceKey = "WindowTextColor",
+ Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
+ Description = "Headings, body copy, lists, placeholder text, app and window borders.",
+ PairWith = "WindowColor"
+ },
+ new ColorResource
+ {
+ ResourceKey = "HotlightColor",
+ Brush = new SolidColorBrush(Color.Parse("#75E9FC")),
+ Description = "Hyperlinks.",
+ PairWith = "WindowColor"
+ },
+ new ColorResource
+ {
+ ResourceKey = "GrayTextColor",
+ Brush = new SolidColorBrush(Color.Parse("#A6A6A6")),
+ Description = "Inactive (disabled) UI.",
+ PairWith = "WindowColor"
+ },
+ new ColorResource
+ {
+ ResourceKey = "HighlightTextColor",
+ Brush = new SolidColorBrush(Color.Parse("#263B50")),
+ Description =
+ "Foreground color for text or UI that is in selected, interacted with (hover, pressed), or in progress.",
+ PairWith = "HighlightColor"
+ },
+ new ColorResource
+ {
+ ResourceKey = "HighlightColor",
+ Brush = new SolidColorBrush(Color.Parse("#8EE3F0")),
+ Description =
+ "Background or accent color for UI that is in selected, interacted with (hover, pressed), or in progress.",
+ PairWith = "HighlightTextColor"
+ },
+ new ColorResource
+ {
+ ResourceKey = "ButtonTextColor",
+ Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
+ Description = "Foreground color for buttons and any UI that can be interacted with.",
+ PairWith = "ButtonFaceColor"
+ },
+ new ColorResource
+ {
+ ResourceKey = "ButtonFaceColor",
+ Brush = new SolidColorBrush(Color.Parse("#202020")),
+ Description = "Background color for buttons and any UI that can be interacted with.",
+ PairWith = "ButtonTextColor"
+ },
+ ];
+ SelectedThemeVariant = SemiTheme.Aquatic;
+ }
+
+ partial void OnSelectedThemeVariantChanged(ThemeVariant? value)
+ {
+ var topLevel = ResolveDefaultTopLevel();
+ if (value is null) return;
+ foreach (var colorResource in ColorResources)
+ {
+ if (colorResource.ResourceKey is null) continue;
+ if (topLevel?.TryFindResource(colorResource.ResourceKey, value, out var o) == true && o is Color color)
+ {
+ colorResource.Brush = new SolidColorBrush(color);
+ }
+ }
+ }
+
+ private static TopLevel? ResolveDefaultTopLevel()
+ {
+ return Application.Current?.ApplicationLifetime switch
+ {
+ IClassicDesktopStyleApplicationLifetime desktopLifetime => desktopLifetime.MainWindow,
+ ISingleViewApplicationLifetime singleView => TopLevel.GetTopLevel(singleView.MainView),
+ _ => null
+ };
+ }
+}
+
+public partial class ColorResource : ObservableObject
+{
+ [ObservableProperty] private string? _resourceKey;
+ [ObservableProperty] private SolidColorBrush? _brush;
+ [ObservableProperty] private string? _description;
+ [ObservableProperty] private string? _pairWith;
+}
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Views/MainView.axaml b/demo/Semi.Avalonia.Demo/Views/MainView.axaml
index ce949a5..44ffb65 100644
--- a/demo/Semi.Avalonia.Demo/Views/MainView.axaml
+++ b/demo/Semi.Avalonia.Demo/Views/MainView.axaml
@@ -110,7 +110,7 @@
-
+
From 329e041ced1f78529515bf791a765a49ec5fc2e9 Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Tue, 24 Dec 2024 16:39:57 +0800
Subject: [PATCH 5/5] feat: add ColorDetail panel.
---
.../Controls/ColorDetailControl.axaml | 7 +-
.../Controls/ColorDetailControl.cs | 54 +-
.../Controls/ColorItemControl.axaml | 20 +-
.../Controls/ColorItemControl.cs | 17 +-
.../Pages/HighContrastDemo.axaml | 535 ++++++++++--------
.../ViewModels/HighContrastDemoViewModel.cs | 15 +
6 files changed, 366 insertions(+), 282 deletions(-)
diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.axaml b/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.axaml
index 4dc7d42..038906c 100644
--- a/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.axaml
+++ b/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.axaml
@@ -1,13 +1,10 @@
+ xmlns:controls="clr-namespace:Semi.Avalonia.Demo.Controls">
M5 7C3.89543 7 3 7.89543 3 9V19C3 20.1046 3.89543 21 5 21H15C16.1046 21 17 20.1046 17 19V9C17 7.89543 16.1046 7 15 7H5Z,M7 4C7 2.89543 7.89543 2 9 2H20C21.1046 2 22 2.89543 22 4V15C22 16.1046 21.1046 17 20 17H19V8C19 6 18 5 16 5H7V4Z
-
+
ResourceKeyProperty = AvaloniaProperty.Register(
- nameof(ResourceKey));
+
+ public static readonly StyledProperty ResourceKeyProperty =
+ AvaloniaProperty.Register(nameof(ResourceKey));
+
public string? ResourceKey
{
get => GetValue(ResourceKeyProperty);
set => SetValue(ResourceKeyProperty, value);
}
- public static readonly StyledProperty ResourceNameProperty = AvaloniaProperty.Register(
- nameof(ResourceName));
+ public static readonly StyledProperty ResourceNameProperty =
+ AvaloniaProperty.Register(nameof(ResourceName));
public string? ResourceName
{
@@ -32,8 +31,8 @@ public class ColorDetailControl: TemplatedControl
set => SetValue(ResourceNameProperty, value);
}
- public static readonly StyledProperty ColorResourceKeyProperty = AvaloniaProperty.Register(
- nameof(ColorResourceKey));
+ public static readonly StyledProperty ColorResourceKeyProperty =
+ AvaloniaProperty.Register(nameof(ColorResourceKey));
public string? ColorResourceKey
{
@@ -41,27 +40,28 @@ public class ColorDetailControl: TemplatedControl
set => SetValue(ColorResourceKeyProperty, value);
}
- public static readonly DirectProperty HexProperty = AvaloniaProperty.RegisterDirect(
- nameof(Hex), o => o.Hex);
+ public static readonly DirectProperty HexProperty =
+ AvaloniaProperty.RegisterDirect(nameof(Hex), o => o.Hex);
+
private string? _hex;
+
public string? Hex
{
get => _hex;
private set => SetAndRaise(HexProperty, ref _hex, value);
}
-
- public static readonly DirectProperty OpacityNumberProperty = AvaloniaProperty.RegisterDirect(
- nameof(OpacityNumber), o => o.OpacityNumber);
+
+ public static readonly DirectProperty OpacityNumberProperty =
+ AvaloniaProperty.RegisterDirect(nameof(OpacityNumber), o => o.OpacityNumber);
+
private string? _opacityNumber;
+
public string? OpacityNumber
{
get => _opacityNumber;
private set => SetAndRaise(OpacityNumberProperty, ref _opacityNumber, value);
}
-
-
-
-
+
static ColorDetailControl()
{
BackgroundProperty.Changed.AddClassHandler((o, e) => o.OnBackgroundChanged(e));
@@ -84,13 +84,17 @@ public class ColorDetailControl: TemplatedControl
{
switch (s)
{
- case KEY_ResourceKey: text = ResourceKey;
+ case KEY_ResourceKey:
+ text = ResourceKey;
break;
- case KEY_Hex: text = Hex;
+ case KEY_Hex:
+ text = Hex;
break;
- case KEY_Opacity: text = OpacityNumber;
+ case KEY_Opacity:
+ text = OpacityNumber;
break;
- case KEY_ColorResourceKey: text = ColorResourceKey;
+ case KEY_ColorResourceKey:
+ text = ColorResourceKey;
break;
default: text = string.Empty; break;
}
@@ -99,9 +103,7 @@ public class ColorDetailControl: TemplatedControl
var toplevel = TopLevel.GetTopLevel(this);
if (toplevel?.Clipboard is { } c)
{
- await c.SetTextAsync(text??string.Empty);
+ await c.SetTextAsync(text ?? string.Empty);
}
-
}
-
}
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml
index 6e2cd4e..7169196 100644
--- a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml
+++ b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml
@@ -1,25 +1,23 @@
+ xmlns:controls="using:Semi.Avalonia.Demo.Controls">
-
-
-
-
+
+
+
+
-
-
+
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.cs b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.cs
index 04c8000..b73cf5e 100644
--- a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.cs
+++ b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.cs
@@ -1,5 +1,4 @@
using Avalonia;
-using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using CommunityToolkit.Mvvm.Messaging;
@@ -9,8 +8,8 @@ namespace Semi.Avalonia.Demo.Controls;
public class ColorItemControl : TemplatedControl
{
- public static readonly StyledProperty ColorNameProperty = AvaloniaProperty.Register(
- nameof(ColorName));
+ public static readonly StyledProperty ColorNameProperty =
+ AvaloniaProperty.Register(nameof(ColorName));
public string? ColorName
{
@@ -26,14 +25,18 @@ public class ColorItemControl : TemplatedControl
get => GetValue(HexProperty);
set => SetValue(HexProperty, value);
}
-
+
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
- if (this.DataContext is ColorItemViewModel v)
+ switch (this.DataContext)
{
- WeakReferenceMessenger.Default.Send(v);
+ case ColorItemViewModel colorItemViewModel:
+ WeakReferenceMessenger.Default.Send(colorItemViewModel);
+ break;
+ case ColorResource colorResource:
+ WeakReferenceMessenger.Default.Send(colorResource);
+ break;
}
-
}
}
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
index 630b0b8..4639ee9 100644
--- a/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
+++ b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
@@ -3,249 +3,318 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Semi.Avalonia.Demo.ViewModels"
+ xmlns:controls="clr-namespace:Semi.Avalonia.Demo.Controls"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1450"
x:DataType="vm:HighContrastDemoViewModel"
x:Class="Semi.Avalonia.Demo.Pages.HighContrastDemo">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs
index df80437..968aefa 100644
--- a/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs
+++ b/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs
@@ -6,12 +6,15 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Media;
using Avalonia.Styling;
using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Messaging;
namespace Semi.Avalonia.Demo.ViewModels;
public partial class HighContrastDemoViewModel : ObservableObject
{
[ObservableProperty] private ThemeVariant? _selectedThemeVariant;
+ [ObservableProperty] private ColorResource _selectedColorResource = null!;
+
public IEnumerable ThemeVariants { get; }
public ObservableCollection ColorResources { get; set; }
@@ -30,6 +33,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
{
ResourceKey = "WindowColor",
Brush = new SolidColorBrush(Color.Parse("#202020")),
+ Hex = "#FF202020",
Description = "Background of pages, panes, popups, and windows.",
PairWith = "WindowTextColor"
},
@@ -37,6 +41,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
{
ResourceKey = "WindowTextColor",
Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
+ Hex = "WHITE",
Description = "Headings, body copy, lists, placeholder text, app and window borders.",
PairWith = "WindowColor"
},
@@ -44,6 +49,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
{
ResourceKey = "HotlightColor",
Brush = new SolidColorBrush(Color.Parse("#75E9FC")),
+ Hex = "#FF75E9FC",
Description = "Hyperlinks.",
PairWith = "WindowColor"
},
@@ -51,6 +57,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
{
ResourceKey = "GrayTextColor",
Brush = new SolidColorBrush(Color.Parse("#A6A6A6")),
+ Hex = "#FFA6A6A6",
Description = "Inactive (disabled) UI.",
PairWith = "WindowColor"
},
@@ -58,6 +65,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
{
ResourceKey = "HighlightTextColor",
Brush = new SolidColorBrush(Color.Parse("#263B50")),
+ Hex = "#FF263B50",
Description =
"Foreground color for text or UI that is in selected, interacted with (hover, pressed), or in progress.",
PairWith = "HighlightColor"
@@ -66,6 +74,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
{
ResourceKey = "HighlightColor",
Brush = new SolidColorBrush(Color.Parse("#8EE3F0")),
+ Hex = "#FF8EE3F0",
Description =
"Background or accent color for UI that is in selected, interacted with (hover, pressed), or in progress.",
PairWith = "HighlightTextColor"
@@ -74,6 +83,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
{
ResourceKey = "ButtonTextColor",
Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
+ Hex = "WHITE",
Description = "Foreground color for buttons and any UI that can be interacted with.",
PairWith = "ButtonFaceColor"
},
@@ -81,10 +91,13 @@ public partial class HighContrastDemoViewModel : ObservableObject
{
ResourceKey = "ButtonFaceColor",
Brush = new SolidColorBrush(Color.Parse("#202020")),
+ Hex = "#FF202020",
Description = "Background color for buttons and any UI that can be interacted with.",
PairWith = "ButtonTextColor"
},
];
+ WeakReferenceMessenger.Default.Register
+ (this, (_, item) => SelectedColorResource = item);
SelectedThemeVariant = SemiTheme.Aquatic;
}
@@ -98,6 +111,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
if (topLevel?.TryFindResource(colorResource.ResourceKey, value, out var o) == true && o is Color color)
{
colorResource.Brush = new SolidColorBrush(color);
+ colorResource.Hex = color.ToString().ToUpperInvariant();
}
}
}
@@ -117,6 +131,7 @@ public partial class ColorResource : ObservableObject
{
[ObservableProperty] private string? _resourceKey;
[ObservableProperty] private SolidColorBrush? _brush;
+ [ObservableProperty] private string? _hex;
[ObservableProperty] private string? _description;
[ObservableProperty] private string? _pairWith;
}
\ No newline at end of file