From 3b346b57820e004da7333bafe4c2591d688836de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Mon, 8 Aug 2022 08:01:47 +0200 Subject: [PATCH] Add project files. --- QuickMVVMSetup.sln | 25 ++++++++++ QuickMVVMSetup/AddCommand.cs | 30 ++++++++++++ QuickMVVMSetup/App.xaml | 9 ++++ QuickMVVMSetup/App.xaml.cs | 17 +++++++ QuickMVVMSetup/AssemblyInfo.cs | 10 ++++ QuickMVVMSetup/ChangeNotifier.cs | 20 ++++++++ QuickMVVMSetup/MainVM.cs | 47 +++++++++++++++++++ QuickMVVMSetup/MainWindow.xaml | 69 ++++++++++++++++++++++++++++ QuickMVVMSetup/MainWindow.xaml.cs | 31 +++++++++++++ QuickMVVMSetup/Person.cs | 39 ++++++++++++++++ QuickMVVMSetup/QuickMVVMSetup.csproj | 14 ++++++ QuickMVVMSetup/RelayCommand.cs | 35 ++++++++++++++ 12 files changed, 346 insertions(+) create mode 100644 QuickMVVMSetup.sln create mode 100644 QuickMVVMSetup/AddCommand.cs create mode 100644 QuickMVVMSetup/App.xaml create mode 100644 QuickMVVMSetup/App.xaml.cs create mode 100644 QuickMVVMSetup/AssemblyInfo.cs create mode 100644 QuickMVVMSetup/ChangeNotifier.cs create mode 100644 QuickMVVMSetup/MainVM.cs create mode 100644 QuickMVVMSetup/MainWindow.xaml create mode 100644 QuickMVVMSetup/MainWindow.xaml.cs create mode 100644 QuickMVVMSetup/Person.cs create mode 100644 QuickMVVMSetup/QuickMVVMSetup.csproj create mode 100644 QuickMVVMSetup/RelayCommand.cs diff --git a/QuickMVVMSetup.sln b/QuickMVVMSetup.sln new file mode 100644 index 0000000..0096bf8 --- /dev/null +++ b/QuickMVVMSetup.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32630.192 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickMVVMSetup", "QuickMVVMSetup\QuickMVVMSetup.csproj", "{ABD27BDD-F092-4031-9233-1D09D67B639E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ABD27BDD-F092-4031-9233-1D09D67B639E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABD27BDD-F092-4031-9233-1D09D67B639E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABD27BDD-F092-4031-9233-1D09D67B639E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABD27BDD-F092-4031-9233-1D09D67B639E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {53E0FF96-FCE2-449B-9D8F-1892D63E50EF} + EndGlobalSection +EndGlobal diff --git a/QuickMVVMSetup/AddCommand.cs b/QuickMVVMSetup/AddCommand.cs new file mode 100644 index 0000000..505ef43 --- /dev/null +++ b/QuickMVVMSetup/AddCommand.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace QuickMVVMSetup +{ + public class AddCommand : ICommand + { + public event EventHandler? CanExecuteChanged; + public MainVM assosiatedVM; + + public bool CanExecute(object parameter) + { + return true; + } + + public void Execute(object parameter) + { + assosiatedVM.AddPerson(); + } + + public AddCommand(MainVM vm) + { + assosiatedVM = vm; + } + } +} diff --git a/QuickMVVMSetup/App.xaml b/QuickMVVMSetup/App.xaml new file mode 100644 index 0000000..fda988d --- /dev/null +++ b/QuickMVVMSetup/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/QuickMVVMSetup/App.xaml.cs b/QuickMVVMSetup/App.xaml.cs new file mode 100644 index 0000000..3144c13 --- /dev/null +++ b/QuickMVVMSetup/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace QuickMVVMSetup +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/QuickMVVMSetup/AssemblyInfo.cs b/QuickMVVMSetup/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/QuickMVVMSetup/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/QuickMVVMSetup/ChangeNotifier.cs b/QuickMVVMSetup/ChangeNotifier.cs new file mode 100644 index 0000000..7c51a4f --- /dev/null +++ b/QuickMVVMSetup/ChangeNotifier.cs @@ -0,0 +1,20 @@ +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 new file mode 100644 index 0000000..2112f06 --- /dev/null +++ b/QuickMVVMSetup/MainVM.cs @@ -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 _persons; //only when added/or removed (not for internal property changes) + + public ObservableCollection 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(); + } +} diff --git a/QuickMVVMSetup/MainWindow.xaml b/QuickMVVMSetup/MainWindow.xaml new file mode 100644 index 0000000..c0107c0 --- /dev/null +++ b/QuickMVVMSetup/MainWindow.xaml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + +