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] 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 @@
-
+