diff --git a/demo/Semi.Avalonia.Demo/Pages/VariablesDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/VariablesDemo.axaml
index 44c41f3..23aad9d 100644
--- a/demo/Semi.Avalonia.Demo/Pages/VariablesDemo.axaml
+++ b/demo/Semi.Avalonia.Demo/Pages/VariablesDemo.axaml
@@ -3,6 +3,7 @@
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:pages="clr-namespace:Semi.Avalonia.Demo.Pages"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Semi.Avalonia.Demo.Pages.VariablesDemo"
x:DataType="vm:VariablesDemoViewModel">
@@ -33,10 +34,18 @@
-
+
+
+
+
@@ -50,10 +59,20 @@
-
+
+
+
+
diff --git a/demo/Semi.Avalonia.Demo/Pages/VariablesDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/VariablesDemo.axaml.cs
index bc459b5..76afc89 100644
--- a/demo/Semi.Avalonia.Demo/Pages/VariablesDemo.axaml.cs
+++ b/demo/Semi.Avalonia.Demo/Pages/VariablesDemo.axaml.cs
@@ -1,4 +1,5 @@
-using Avalonia.Controls;
+using System.Threading.Tasks;
+using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Threading;
using Semi.Avalonia.Demo.ViewModels;
@@ -19,4 +20,14 @@ public partial class VariablesDemo : UserControl
var vm = this.DataContext as VariablesDemoViewModel;
await Dispatcher.UIThread.InvokeAsync(() => { vm?.InitializeResources(); });
}
+
+ 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/VariablesDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/VariablesDemoViewModel.cs
index 6ce4475..1e08620 100644
--- a/demo/Semi.Avalonia.Demo/ViewModels/VariablesDemoViewModel.cs
+++ b/demo/Semi.Avalonia.Demo/ViewModels/VariablesDemoViewModel.cs
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Globalization;
+using Avalonia;
using Avalonia.Controls;
+using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using Semi.Avalonia.Demo.Constant;
using Semi.Avalonia.Tokens;
@@ -46,10 +49,25 @@ public partial class VariableGridViewModel : ObservableObject
{
if (dictionary?.TryGetValue(key, out var value) ?? false)
{
- VariableItems.Add(new VariableItemViewModel(name, value ?? string.Empty, key));
+ VariableItems.Add(new VariableItemViewModel(name, GetValueString(value), key));
}
}
}
+
+ private static string GetValueString(object? value)
+ {
+ if (value is null) return string.Empty;
+
+ return value switch
+ {
+ double d => d.ToString(CultureInfo.InvariantCulture),
+ CornerRadius c => c.IsUniform ? $"{c.TopLeft}" : c.ToString(),
+ Thickness t => t.IsUniform ? $"{t.Left}" : t.ToString(),
+ FontWeight fontWeight => Convert.ToInt32(fontWeight).ToString(),
+ FontFamily fontFamily => fontFamily.FamilyNames.ToString(),
+ _ => value.ToString()
+ };
+ }
}
public partial class VariableItemViewModel : ObservableObject