diff --git a/MVVMwithWPF/MVVMwithWPF/App.xaml b/MVVMwithWPF/MVVMwithWPF/App.xaml index 54ba07c..f6cd562 100644 --- a/MVVMwithWPF/MVVMwithWPF/App.xaml +++ b/MVVMwithWPF/MVVMwithWPF/App.xaml @@ -2,6 +2,6 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MVVMwithWPF" - StartupUri="/Views/ConverterWindoew.xaml"> + StartupUri="/Views/CommandWindow.xaml"> diff --git a/MVVMwithWPF/MVVMwithWPF/Models/Person.cs b/MVVMwithWPF/MVVMwithWPF/Models/Person.cs index 5ecbd40..82ba222 100644 --- a/MVVMwithWPF/MVVMwithWPF/Models/Person.cs +++ b/MVVMwithWPF/MVVMwithWPF/Models/Person.cs @@ -13,5 +13,6 @@ namespace MVVMwithWPF.Models public string Name { get; set; } public bool Sex { get; set; } public string DepartmentCode { get; set; } + public string Description { get; set; } } } diff --git a/MVVMwithWPF/MVVMwithWPF/ViewModels/CommandViewModel.cs b/MVVMwithWPF/MVVMwithWPF/ViewModels/CommandViewModel.cs new file mode 100644 index 0000000..8c56f47 --- /dev/null +++ b/MVVMwithWPF/MVVMwithWPF/ViewModels/CommandViewModel.cs @@ -0,0 +1,84 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using MVVMwithWPF.Models; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace MVVMwithWPF.ViewModels +{ + public partial class CommandViewModel : ObservableObject + { + + + [ObservableProperty] + private ObservableCollection _people; + + + [ObservableProperty] + private Person _selectedPerson; + + + [ObservableProperty] + private string _message; + + + [ObservableProperty] + private bool _isBusy; + + public CommandViewModel() + { + People = new ObservableCollection() + { + new Person() { Id = 1, Name = "user001", Sex = true, DepartmentCode = "01"}, + new Person() { Id = 2, Name = "user002", Sex = false, DepartmentCode = "02"}, + new Person() { Id = 3, Name = "user003", Sex = true, DepartmentCode = "03"}, + new Person() { Id = 4, Name = "user004", Sex = false, DepartmentCode = "02"}, + new Person() { Id = 5, Name = "user005", Sex = true, DepartmentCode = "01"}, + }; + } + + [RelayCommand] + private void Delete() + { + if (MessageBox.Show("선택한 아이템을 삭제하시겠습니까?", "확인", MessageBoxButton.OKCancel) != MessageBoxResult.OK) + return; + + People.Remove(SelectedPerson); + } + + [RelayCommand] + private void AddNewItem(object obj) + { + if (obj is AddingNewItemEventArgs args) + args.NewItem = new Person() { Id = People.Max(p => p.Id) + 1 }; + } + + [RelayCommand] + private void SelectionChanged(Person obj) + { + Message = obj == null ? "선택한 아이템이 없습니다." : $"{obj.Name}을/를 선택했습니다."; + SelectedPerson = obj; + } + + [RelayCommand] + private void Normal() + { + Message = "Normal 버튼을 클릭했습니다."; + } + + [RelayCommand] + private async Task AsyncNormal() + { + Message = "비동기 Noraml 버튼 클릭 시작"; + await Task.Delay(3000); + Message = "비동기 Noraml 버튼 클릭 종료"; + } + } +} diff --git a/MVVMwithWPF/MVVMwithWPF/Views/CommandWindow.xaml b/MVVMwithWPF/MVVMwithWPF/Views/CommandWindow.xaml new file mode 100644 index 0000000..f8952b5 --- /dev/null +++ b/MVVMwithWPF/MVVMwithWPF/Views/CommandWindow.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + +