feat: enhance IconDemo.

This commit is contained in:
Zhang Dian
2024-12-20 21:56:04 +08:00
parent de58cf9f3d
commit 9ef0e418b8
3 changed files with 82 additions and 30 deletions

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.ObjectModel;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
namespace Semi.Avalonia.Demo.ViewModels;
public partial class IconDemoViewModel : ObservableObject
{
private readonly IResourceDictionary? _resources =
AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Shared/Icon.axaml")) as ResourceDictionary;
public ObservableCollection<IconItem> Icons { get; set; } = [];
public void InitializeResources()
{
LoadIcons();
}
private void LoadIcons()
{
if (_resources is null) return;
foreach (var key in _resources.Keys)
{
if (_resources[key] is Geometry geometry)
{
var icon = new IconItem { ResourceKey = key.ToString(), Geometry = geometry };
Icons.Add(icon);
}
}
}
}
public class IconItem
{
public string? ResourceKey { get; set; }
public Geometry? Geometry { get; set; }
}