view delete me/SilverlightValidation/ViewModels/UserListViewModel.cs @ 81:4ea16a799a03

upload ready after tidy up
author Steven Hollidge <stevenhollidge@hotmail.com>
date Mon, 23 Apr 2012 23:20:01 +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
    }
}