From b5fe4d92a61d9ea8ef285fedce3e6eebe9ce117d Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Tue, 21 Jan 2025 21:17:20 +0800
Subject: [PATCH] feat: add CopyText to HighContrastDemo.
---
.../Pages/HighContrastDemo.axaml | 22 +++++++++++++
.../Pages/HighContrastDemo.axaml.cs | 13 +++++++-
.../ViewModels/HighContrastDemoViewModel.cs | 33 ++++++++++++-------
3 files changed, 56 insertions(+), 12 deletions(-)
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
index 03599ec..78116ef 100644
--- a/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
+++ b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml
@@ -5,6 +5,7 @@
xmlns:vm="clr-namespace:Semi.Avalonia.Demo.ViewModels"
xmlns:controls="clr-namespace:Semi.Avalonia.Demo.Controls"
xmlns:cvt="clr-namespace:Semi.Avalonia.Demo.Converters"
+ xmlns:pages="clr-namespace:Semi.Avalonia.Demo.Pages"
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1450"
x:DataType="vm:HighContrastDemoViewModel"
x:CompileBindings="True"
@@ -306,6 +307,27 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml.cs
index e8f4350..2d42757 100644
--- a/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml.cs
+++ b/demo/Semi.Avalonia.Demo/Pages/HighContrastDemo.axaml.cs
@@ -1,4 +1,5 @@
-using Avalonia.Controls;
+using System.Threading.Tasks;
+using Avalonia.Controls;
using Semi.Avalonia.Demo.ViewModels;
namespace Semi.Avalonia.Demo.Pages;
@@ -10,4 +11,14 @@ public partial class HighContrastDemo : UserControl
InitializeComponent();
this.DataContext = new HighContrastDemoViewModel();
}
+
+ public async Task Copy(object? o)
+ {
+ if (o is null) return;
+ var toplevel = TopLevel.GetTopLevel(this);
+ if (toplevel?.Clipboard is { } c)
+ {
+ await c.SetTextAsync(o.ToString());
+ }
+ }
}
\ 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 1ddb8e0..3043047 100644
--- a/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs
+++ b/demo/Semi.Avalonia.Demo/ViewModels/HighContrastDemoViewModel.cs
@@ -31,35 +31,35 @@ public partial class HighContrastDemoViewModel : ObservableObject
[
new ColorResource
{
- ResourceKey = "WindowColor",
+ ResourceKey = "SemiColorWindow",
Brush = new SolidColorBrush(Color.Parse("#202020")),
Description = "Background of pages, panes, popups, and windows.",
PairWith = "WindowTextColor"
},
new ColorResource
{
- ResourceKey = "WindowTextColor",
+ ResourceKey = "SemiColorWindowText",
Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
Description = "Headings, body copy, lists, placeholder text, app and window borders.",
PairWith = "WindowColor"
},
new ColorResource
{
- ResourceKey = "HotlightColor",
+ ResourceKey = "SemiColorHotlight",
Brush = new SolidColorBrush(Color.Parse("#75E9FC")),
Description = "Hyperlinks.",
PairWith = "WindowColor"
},
new ColorResource
{
- ResourceKey = "GrayTextColor",
+ ResourceKey = "SemiColorGrayText",
Brush = new SolidColorBrush(Color.Parse("#A6A6A6")),
Description = "Inactive (disabled) UI.",
PairWith = "WindowColor"
},
new ColorResource
{
- ResourceKey = "HighlightTextColor",
+ ResourceKey = "SemiColorHighlightText",
Brush = new SolidColorBrush(Color.Parse("#263B50")),
Description =
"Foreground color for text or UI that is in selected, interacted with (hover, pressed), or in progress.",
@@ -67,7 +67,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
},
new ColorResource
{
- ResourceKey = "HighlightColor",
+ ResourceKey = "SemiColorHighlight",
Brush = new SolidColorBrush(Color.Parse("#8EE3F0")),
Description =
"Background or accent color for UI that is in selected, interacted with (hover, pressed), or in progress.",
@@ -75,14 +75,14 @@ public partial class HighContrastDemoViewModel : ObservableObject
},
new ColorResource
{
- ResourceKey = "ButtonTextColor",
+ ResourceKey = "SemiColorButtonText",
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",
+ ResourceKey = "SemiColorButtonFace",
Brush = new SolidColorBrush(Color.Parse("#202020")),
Description = "Background color for buttons and any UI that can be interacted with.",
PairWith = "ButtonTextColor"
@@ -100,9 +100,10 @@ public partial class HighContrastDemoViewModel : ObservableObject
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)
+ if (topLevel?.TryFindResource(colorResource.ResourceKey, value, out var o) == true
+ && o is ISolidColorBrush color)
{
- colorResource.Brush = new SolidColorBrush(color);
+ colorResource.Brush = color;
}
}
}
@@ -121,7 +122,17 @@ public partial class HighContrastDemoViewModel : ObservableObject
public partial class ColorResource : ObservableObject
{
[ObservableProperty] private string? _resourceKey;
- [ObservableProperty] private SolidColorBrush? _brush;
+ [ObservableProperty] private ISolidColorBrush? _brush;
[ObservableProperty] private string? _description;
[ObservableProperty] private string? _pairWith;
+
+ public string CopyText1 =>
+ $"""
+
+ """;
+
+ public string CopyText2 =>
+ $"""
+
+ """;
}
\ No newline at end of file