You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
72 lines
2.1 KiB
using CommandPatternSample.Command;
|
|
using CommandPatternSample.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CommandPatternSample.ViewModel
|
|
{
|
|
internal class EmpViewModel : INotifyPropertyChanged
|
|
{
|
|
private Emp _selectedEmp;
|
|
private ObservableCollection<Emp> _emps;
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
public RelayCommand AddEmpCommand { get; set; }
|
|
|
|
|
|
public EmpViewModel()
|
|
{
|
|
this.Emps = new ObservableCollection<Emp>();
|
|
this.Emps.Add(new Emp() { Name = "Tom", Job = "Sales" });
|
|
this.Emps.Add(new Emp() { Name = "Jack", Job = "Clerk" });
|
|
this.Emps.Add(new Emp() { Name = "Phinix", Job = "Manager" });
|
|
this.Emps.Add(new Emp() { Name = "John", Job = "Sales" });
|
|
this.Emps.Add(new Emp() { Name = "Richard", Job = "Cleaning" });
|
|
|
|
this.AddEmpCommand = new RelayCommand(new Action<object>(AddEmp));
|
|
}
|
|
|
|
public Emp SelectedEmp
|
|
{
|
|
get { return _selectedEmp; }
|
|
set
|
|
{
|
|
_selectedEmp = value;
|
|
this.OnPropertyChanged(nameof(SelectedEmp));
|
|
}
|
|
}
|
|
|
|
public ObservableCollection<Emp> Emps
|
|
{
|
|
get { return _emps; }
|
|
set
|
|
{
|
|
_emps = value;
|
|
this.OnPropertyChanged(nameof(Emps));
|
|
}
|
|
}
|
|
|
|
public void AddEmp(object param)
|
|
{
|
|
if (string.IsNullOrEmpty(param.ToString()))
|
|
return;
|
|
|
|
this.Emps.Add(new Emp { Name = param.ToString(), Job = "New Job" });
|
|
}
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|
{
|
|
if (this.PropertyChanged == null)
|
|
return;
|
|
|
|
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
}
|
|
}
|
|
|