From f8bc61327c1dab4f08d037fb40bc7dc117b5da3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Mon, 8 Aug 2022 09:05:30 +0200 Subject: [PATCH] Easier workings with Haley MVVM --- QuickMVVMSetup/ChangeNotifier.cs | 20 ---------------- QuickMVVMSetup/MainVM.cs | 17 +++++++++++--- QuickMVVMSetup/MainWindow.xaml | 9 +++++-- QuickMVVMSetup/Person.cs | 5 +++- QuickMVVMSetup/QuickMVVMSetup.csproj | 4 ++++ QuickMVVMSetup/RelayCommand.cs | 35 ---------------------------- 6 files changed, 29 insertions(+), 61 deletions(-) delete mode 100644 QuickMVVMSetup/ChangeNotifier.cs delete mode 100644 QuickMVVMSetup/RelayCommand.cs diff --git a/QuickMVVMSetup/ChangeNotifier.cs b/QuickMVVMSetup/ChangeNotifier.cs deleted file mode 100644 index 7c51a4f..0000000 --- a/QuickMVVMSetup/ChangeNotifier.cs +++ /dev/null @@ -1,20 +0,0 @@ -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 ChangeNotifier : INotifyPropertyChanged - { - public event PropertyChangedEventHandler? PropertyChanged; - protected void OnPropertyChanged(string propName) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName)); - } - } -} diff --git a/QuickMVVMSetup/MainVM.cs b/QuickMVVMSetup/MainVM.cs index 2112f06..e53d692 100644 --- a/QuickMVVMSetup/MainVM.cs +++ b/QuickMVVMSetup/MainVM.cs @@ -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(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(); + TargetPerson = new Person(); } } diff --git a/QuickMVVMSetup/MainWindow.xaml b/QuickMVVMSetup/MainWindow.xaml index c0107c0..9cde7b2 100644 --- a/QuickMVVMSetup/MainWindow.xaml +++ b/QuickMVVMSetup/MainWindow.xaml @@ -43,9 +43,14 @@ -