feat: Add HoneycombPanel and demo.

This commit is contained in:
NaBian committed 2026-06-13 16:16:48 +08:00
1 parent d1944b01c3
commit e7005d09b5
16 files changed
+263 -1

No files matched your search

@@ -0,0 +1,42 @@
using System;
using System.Collections.ObjectModel;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace HandyControlDemo.ViewModel;
public partial class HoneycombPanelDemoViewModel : ObservableObject
{
private static readonly Random Random = new();
[ObservableProperty] private ObservableCollection<Bitmap> _dataList = [];
public HoneycombPanelDemoViewModel()
{
for (int i = 0; i < 7; i++)
{
DataList.Add(LoadRandomAvatar());
}
}
[RelayCommand]
private void AddItem() => DataList.Insert(0, LoadRandomAvatar());
[RelayCommand]
private void RemoveItem()
{
if (DataList.Count > 0)
{
DataList.RemoveAt(0);
}
}
private static Bitmap LoadRandomAvatar()
{
var uri = new Uri($"avares://HandyControlDemo/Resources/Img/Avatar/avatar{Random.Next(1, 7)}.png");
using var stream = AssetLoader.Open(uri);
return new Bitmap(stream);
}
}
@@ -20,6 +20,7 @@ public class ViewModelLocator
services.AddSingleton<DataService>();
services.AddTransient<MainViewModel>();
services.AddTransient<InputElementDemoViewModel>();
services.AddTransient<HoneycombPanelDemoViewModel>();
_serviceProvider = services.BuildServiceProvider();
}
@@ -27,4 +28,6 @@ public class ViewModelLocator
public MainViewModel Main => _serviceProvider.GetService<MainViewModel>()!;
public InputElementDemoViewModel InputElementDemo => _serviceProvider.GetService<InputElementDemoViewModel>()!;
public HoneycombPanelDemoViewModel HoneycombPanelDemo => _serviceProvider.GetService<HoneycombPanelDemoViewModel>()!;
}