feat: add CopyText to PaletteDemo.

This commit is contained in:
Zhang Dian
2025-01-21 20:24:21 +08:00
parent 232ce71677
commit e981fe1c82
4 changed files with 102 additions and 37 deletions

View File

@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Threading;
@@ -19,4 +20,14 @@ public partial class PaletteDemo : UserControl
PaletteDemoViewModel? vm = this.DataContext as PaletteDemoViewModel;
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());
}
}
}