2025-01-21 20:24:21 +08:00
|
|
|
using System.Threading.Tasks;
|
2023-02-11 15:50:39 +08:00
|
|
|
using Avalonia.Controls;
|
2023-02-13 02:55:29 +08:00
|
|
|
using Avalonia.Controls.Primitives;
|
2026-02-06 20:24:35 +08:00
|
|
|
using Avalonia.Input.Platform;
|
2023-02-13 03:29:56 +08:00
|
|
|
using Avalonia.Threading;
|
2023-02-11 23:04:07 +08:00
|
|
|
using Semi.Avalonia.Demo.ViewModels;
|
2023-02-11 15:50:39 +08:00
|
|
|
|
|
|
|
|
namespace Semi.Avalonia.Demo.Pages;
|
|
|
|
|
|
|
|
|
|
public partial class PaletteDemo : UserControl
|
|
|
|
|
{
|
|
|
|
|
public PaletteDemo()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-10-03 00:17:19 +08:00
|
|
|
this.DataContext = new PaletteDemoViewModel();
|
2023-02-13 02:55:29 +08:00
|
|
|
}
|
|
|
|
|
|
2025-01-21 18:51:45 +08:00
|
|
|
protected override async void OnApplyTemplate(TemplateAppliedEventArgs e)
|
2023-02-13 02:55:29 +08:00
|
|
|
{
|
|
|
|
|
base.OnApplyTemplate(e);
|
2024-10-03 00:17:19 +08:00
|
|
|
PaletteDemoViewModel? vm = this.DataContext as PaletteDemoViewModel;
|
2025-01-21 18:51:45 +08:00
|
|
|
await Dispatcher.UIThread.InvokeAsync(() => { vm?.InitializeResources(); });
|
2023-02-11 15:50:39 +08:00
|
|
|
}
|
2025-01-21 20:24:21 +08:00
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-11 15:50:39 +08:00
|
|
|
}
|