|
|
|
@ -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<Person> _people; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private Person _selectedPerson; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private string _message; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private bool _isBusy; |
|
|
|
|
|
|
|
|
|
public CommandViewModel() |
|
|
|
|
{ |
|
|
|
|
People = new ObservableCollection<Person>() |
|
|
|
|
{ |
|
|
|
|
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 버튼 클릭 종료"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |