using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
namespace WpfApp026
{
public class ViewModel
{
static int index =100;
public ViewModel()
{
for (int i =1; i < 9; i++)
{
Data d = new Data() { ID = index++, Name = $"Имя {index}", Description = $"Описание {index}", Parent=col };
col.Add(d);
for (int k = 1; k < 9; k++)
d.SubItems.Add(new Data() {ID= index++, Name = $"Имя {index}", Description = $"Описание {index}", Parent=d.SubItems });
}
cvs.Source = col;
}
private ObservableCollection col = new ObservableCollection();
private CollectionViewSource cvs = new CollectionViewSource();
public ICollectionView View { get => cvs.View; }
public ICommand Add { get => new RelayCommand(CmdAdd); }
public ICommand Del { get => new RelayCommand(CmdDel); }
private void CmdAdd(object obj)
{
Data d0 = obj as Data;
d0?.SubItems.Add(new Data() { ID = index++, Name = $"Имя {index}", Description = $"Описание {index}", Parent = d0.SubItems });
}
private void CmdDel(object obj)
{
Data d = obj as Data;
d?.Parent.Remove(d);
}
}
public class Data
{
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public ObservableCollection SubItems { get; set; }= new ObservableCollection { };
public ObservableCollection Parent { get; set; }
}
public class RelayCommand : ICommand
{
private readonly Predicate