Easier workings with Haley MVVM

This commit is contained in:
2022-08-08 09:05:30 +02:00
parent 3b346b5782
commit f8bc61327c
6 changed files with 29 additions and 61 deletions

View File

@ -6,6 +6,9 @@ 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;
@ -28,7 +31,7 @@ public class MainVM : ChangeNotifier
set { _persons = value; }
}
public void AddPerson(object person)
public void AddPerson()
{
Persons.Add(TargetPerson); // Adding to collection
TargetPerson = new Person(); //Resetting it
@ -36,12 +39,20 @@ public class MainVM : ChangeNotifier
//public ICommand CMDAdd { get; set; }
public ICommand CMDAdd => new RelayCommand(AddPerson,null);
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);
//TargetPerson = new Person();
Persons = new ObservableCollection<Person>();
TargetPerson = new Person();
}
}