view delete me/SilverlightValidation/ViewModels/UserListViewModel.cs @ 62:810116cd6b8e

ErrorWindow working
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sun, 22 Apr 2012 09:01:20 +0100
parents 3591c26bd63e
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
    }
}