view 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 source

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
    }
}