using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; namespace WpfSample.ViewModels { internal partial class MainViewModel: ObservableObject { public MainViewModel() { Random random = new Random(); for (int i = random.Next(1, 10); i >= 0; --i) { Groups.Add(new DemoGroupViewModel() { Name = $"G{i}", }); } } [ObservableProperty] private string message = string.Empty; public ObservableCollection Groups { get; set; } = new ObservableCollection(); class Test { public string Name { get; set; } = string.Empty; } [RelayCommand] private void AddItem() { Groups[0].AddItemCommand?.Execute(null); } } }