feat: add mvvm sample.

This commit is contained in:
rabbitism
2024-04-17 20:10:32 +08:00
parent 13a9806e4b
commit 2c471aa3f6
3 changed files with 99 additions and 19 deletions

View File

@@ -1,8 +1,67 @@
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
namespace Ursa.Demo.ViewModels;
public class TreeComboBoxDemoViewModel: ObservableObject
{
public List<TreeComboBoxItemViewModel> Items { get; set; }
public TreeComboBoxDemoViewModel()
{
Items = new List<TreeComboBoxItemViewModel>()
{
new TreeComboBoxItemViewModel()
{
ItemName = "Item 1",
Children = new List<TreeComboBoxItemViewModel>()
{
new TreeComboBoxItemViewModel()
{
ItemName = "Item 1-1",
Children = new List<TreeComboBoxItemViewModel>()
{
new TreeComboBoxItemViewModel()
{
ItemName = "Item 1-1-1"
},
new TreeComboBoxItemViewModel()
{
ItemName = "Item 1-1-2"
}
}
},
new TreeComboBoxItemViewModel()
{
ItemName = "Item 1-2"
}
}
},
new TreeComboBoxItemViewModel()
{
ItemName = "Item 2",
Children = new List<TreeComboBoxItemViewModel>()
{
new TreeComboBoxItemViewModel()
{
ItemName = "Item 2-1"
},
new TreeComboBoxItemViewModel()
{
ItemName = "Item 2-2"
}
}
},
new TreeComboBoxItemViewModel()
{
ItemName = "Item 3"
},
};
}
}
public partial class TreeComboBoxItemViewModel : ObservableObject
{
[ObservableProperty] private string? _itemName;
public List<TreeComboBoxItemViewModel> Children { get; set; } = new ();
}