Add project files.
This commit is contained in:
47
QuickMVVMSetup/MainVM.cs
Normal file
47
QuickMVVMSetup/MainVM.cs
Normal file
@ -0,0 +1,47 @@
|
||||
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;
|
||||
|
||||
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(object person)
|
||||
{
|
||||
Persons.Add(TargetPerson); // Adding to collection
|
||||
TargetPerson = new Person(); //Resetting it
|
||||
}
|
||||
|
||||
|
||||
//public ICommand CMDAdd { get; set; }
|
||||
public ICommand CMDAdd => new RelayCommand(AddPerson,null);
|
||||
|
||||
public MainVM()
|
||||
{
|
||||
//CMDAdd = new AddCommand(this);
|
||||
//TargetPerson = new Person();
|
||||
Persons = new ObservableCollection<Person>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user