feat: Add Card control and card demo with album images.

This commit is contained in:
NaBian committed 2026-06-13 17:15:54 +08:00
1 parent e7005d09b5
commit d6e16736e4
23 files changed
+287 -47

No files matched your search

@@ -0,0 +1,28 @@
using CommunityToolkit.Mvvm.Input;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel;
public partial class CardDemoViewModel : DemoViewModelBase<CardModel>
{
private readonly DataService _dataService;
public CardDemoViewModel(DataService dataService)
{
_dataService = dataService;
DataList = dataService.GetCardDataList();
}
[RelayCommand]
private void AddItem() => DataList.Insert(0, _dataService.GetCardData());
[RelayCommand]
private void RemoveItem()
{
if (DataList.Count > 0)
{
DataList.RemoveAt(0);
}
}
}
@@ -1,42 +0,0 @@
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);
}
}