Easier workings with Haley MVVM
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user