59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.ComponentModel;
|
|
using System.Windows.Input;
|
|
using System.Collections.ObjectModel;
|
|
using Haley.Models;
|
|
using Haley.Abstractions;
|
|
using Haley.MVVM;
|
|
|
|
namespace QuickMVVMSetup;
|
|
|
|
public class MainVM : ChangeNotifier
|
|
{
|
|
|
|
private Person person;
|
|
|
|
public Person TargetPerson
|
|
{
|
|
get { return person; }
|
|
set { person = value; OnPropertyChanged(nameof(TargetPerson)); }
|
|
}
|
|
|
|
private ObservableCollection<Person> _persons; //only when added/or removed (not for internal property changes)
|
|
|
|
public ObservableCollection<Person> Persons
|
|
{
|
|
get { return _persons; }
|
|
set { _persons = value; }
|
|
}
|
|
|
|
public void AddPerson()
|
|
{
|
|
Persons.Add(TargetPerson); // Adding to collection
|
|
TargetPerson = new Person(); //Resetting it
|
|
}
|
|
|
|
|
|
//public ICommand CMDAdd { get; set; }
|
|
public ICommand CMDAdd => new DelegateCommand(AddPerson);
|
|
public ICommand CMDDelete => new DelegateCommand<Person>(DeletePerson);
|
|
|
|
private void DeletePerson(Person obj)
|
|
{
|
|
if (obj == null) return;
|
|
if (!Persons.Contains(obj)) return;
|
|
Persons.Remove(obj);
|
|
}
|
|
|
|
public MainVM()
|
|
{
|
|
//CMDAdd = new AddCommand(this);
|
|
Persons = new ObservableCollection<Person>();
|
|
TargetPerson = new Person();
|
|
}
|
|
}
|