diff --git a/PacticeSolution/MVVMSample/App.xaml b/PacticeSolution/MVVMSample/App.xaml new file mode 100644 index 0000000..37788a7 --- /dev/null +++ b/PacticeSolution/MVVMSample/App.xaml @@ -0,0 +1,8 @@ + + + + diff --git a/PacticeSolution/MVVMSample/App.xaml.cs b/PacticeSolution/MVVMSample/App.xaml.cs new file mode 100644 index 0000000..c4a9ad7 --- /dev/null +++ b/PacticeSolution/MVVMSample/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 MVVMSample +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/PacticeSolution/MVVMSample/AssemblyInfo.cs b/PacticeSolution/MVVMSample/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/PacticeSolution/MVVMSample/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/PacticeSolution/MVVMSample/MVVMSample.csproj b/PacticeSolution/MVVMSample/MVVMSample.csproj new file mode 100644 index 0000000..4106cb0 --- /dev/null +++ b/PacticeSolution/MVVMSample/MVVMSample.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net6.0-windows + enable + true + + + diff --git a/PacticeSolution/MVVMSample/MainWindow.xaml b/PacticeSolution/MVVMSample/MainWindow.xaml new file mode 100644 index 0000000..fc43869 --- /dev/null +++ b/PacticeSolution/MVVMSample/MainWindow.xaml @@ -0,0 +1,11 @@ + + + + diff --git a/PacticeSolution/MVVMSample/MainWindow.xaml.cs b/PacticeSolution/MVVMSample/MainWindow.xaml.cs new file mode 100644 index 0000000..559ab4f --- /dev/null +++ b/PacticeSolution/MVVMSample/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace MVVMSample +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/PacticeSolution/MVVMSample/Model/NotifierMain.cs b/PacticeSolution/MVVMSample/Model/NotifierMain.cs new file mode 100644 index 0000000..e77a42c --- /dev/null +++ b/PacticeSolution/MVVMSample/Model/NotifierMain.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MVVMSample.Model +{ + internal class NotifierMain : INotifyPropertyChanged + { + public event PropertyChangedEventHandler? PropertyChanged; + + public virtual void NotifyChanged(params string[] propertyNames) + { + foreach (string name in propertyNames) + { + OnPropertyChanged(new PropertyChangedEventArgs(name)); + } + } + + protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) + { + if (PropertyChanged != null) + PropertyChanged(this, e); + } + + protected virtual void OnPropertyChanged(string propertyName) + { + if (PropertyChanged != null) + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/PacticeSolution/MVVMSample/Model/ViewModelMain.cs b/PacticeSolution/MVVMSample/Model/ViewModelMain.cs new file mode 100644 index 0000000..a60c224 --- /dev/null +++ b/PacticeSolution/MVVMSample/Model/ViewModelMain.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace MVVMSample.Model +{ + internal class ViewModelMain : NotifierMain + { + private string _firstName; + private string _lastName; + private string _fullName; + private string _birthday; + + private bool _isBirthdayError = false; + + public string FirstName + { + get { return _firstName; } + set + { + _firstName = value; + _fullName = $"{_lastName} {_firstName}"; + NotifyChanged("FirstName", "FullName"); + } + } + + public string LastName + { + get { return _lastName; } + set + { + _lastName = value; + _fullName = $"{_lastName} {_firstName}"; + NotifyChanged("LastName", "FullName"); + } + } + + public string FullName { get { return _fullName; } } + + public string Birthday + { + get { return _birthday; } + set + { + if (Regex.IsMatch(value, "^[0-9]*$")) + { + _birthday = value; + _isBirthdayError = false; + } + else + { + _birthday = value; + _isBirthdayError = true; + } + NotifyChanged("Birthday", "BirthdayError", "BirthdayErrorMessage"); + } + } + + public bool BirthdayError { get { return _isBirthdayError; } } + + public string BirthdayErrorMessage + { + get + { + if (!_isBirthdayError) + return $"Birthday: {_birthday}"; + else + return $"Please input the number value ({Birthday})"; + } + } + } +} diff --git a/PacticeSolution/MVVMSample/View/ViewMain.xaml b/PacticeSolution/MVVMSample/View/ViewMain.xaml new file mode 100644 index 0000000..0cf6d15 --- /dev/null +++ b/PacticeSolution/MVVMSample/View/ViewMain.xaml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PacticeSolution/MVVMSample/View/ViewMain.xaml.cs b/PacticeSolution/MVVMSample/View/ViewMain.xaml.cs new file mode 100644 index 0000000..8a80d4d --- /dev/null +++ b/PacticeSolution/MVVMSample/View/ViewMain.xaml.cs @@ -0,0 +1,34 @@ +using MVVMSample.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace MVVMSample.View +{ + /// + /// ViewMain.xaml에 대한 상호 작용 논리 + /// + public partial class ViewMain : Window + { + public ViewMain() + { + InitializeComponent(); + InitInstance(); + } + + private void InitInstance() + { + //this.DataContext = new ViewModelMain(); + } + } +} diff --git a/PacticeSolution/PacticeSolution.sln b/PacticeSolution/PacticeSolution.sln index 8628fb2..2fe88b7 100644 --- a/PacticeSolution/PacticeSolution.sln +++ b/PacticeSolution/PacticeSolution.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MapFinder", "MapFinder\MapF EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataBindingSample", "DataBindingSample\DataBindingSample.csproj", "{8A3E4E38-6E95-4955-8BFE-6E58F4AECE27}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MVVMSample", "MVVMSample\MVVMSample.csproj", "{FFD799B6-18C5-413B-8984-B44C803473B0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {8A3E4E38-6E95-4955-8BFE-6E58F4AECE27}.Debug|Any CPU.Build.0 = Debug|Any CPU {8A3E4E38-6E95-4955-8BFE-6E58F4AECE27}.Release|Any CPU.ActiveCfg = Release|Any CPU {8A3E4E38-6E95-4955-8BFE-6E58F4AECE27}.Release|Any CPU.Build.0 = Release|Any CPU + {FFD799B6-18C5-413B-8984-B44C803473B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFD799B6-18C5-413B-8984-B44C803473B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFD799B6-18C5-413B-8984-B44C803473B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFD799B6-18C5-413B-8984-B44C803473B0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE