diff delete me/SilverlightValidation/ViewModels/UserListViewModel.cs @ 59:3591c26bd63e

MVVMLight added
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sat, 21 Apr 2012 19:20:28 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/delete me/SilverlightValidation/ViewModels/UserListViewModel.cs	Sat Apr 21 19:20:28 2012 +0100
@@ -0,0 +1,48 @@
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Windows.Input;
+using SilverlightValidation.Commands;
+using SilverlightValidation.Models;
+using SilverlightValidation.Validators;
+
+namespace SilverlightValidation.ViewModels
+{
+    public class UserListViewModel
+    {
+        public UserListViewModel(IList<UserModel> models, UserModelValidator validator)
+        {
+            Data = new ObservableCollection<UserViewModel>();
+
+            foreach (var model in models)
+                Data.Add(new UserViewModel(model, validator));
+
+            AddCommand = new RelayCommand(AddCommandExecute);
+            DeleteCommand = new RelayCommand(DeleteCommandExecute);
+        }
+
+        #region Properties
+
+        public ObservableCollection<UserViewModel> Data { get; set; }
+
+        public UserViewModel SelectedItem { get; set; }
+
+        #endregion
+
+        #region Commands
+
+        public ICommand AddCommand { get; set; }
+        public ICommand DeleteCommand { get; set; }
+
+        private void AddCommandExecute(object obj)
+        {
+
+        }
+
+        private void DeleteCommandExecute(object obj)
+        {
+            Data.Remove(SelectedItem);
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file