public UserDetailPage(UserViewModel userViewModel)
        {
            InitializeComponent();
            if (userViewModel != null) {
                _userViewModel = userViewModel.Clone();
                _originalUserModel = userViewModel;
                Title = "User Details";
                _userNameTbx.IsEnabled = false;
            } else {
                _userViewModel = new UserViewModel();
                Title = "Add User";
            }
            DataContext = _userViewModel;
            _groupsTreeViewModel = new GroupsTreeViewModel(FakeDataService.GetGroupsTree());
            _candidateGroupsTree.DataContext = _groupsTreeViewModel;

            membershipListBox.SelectionChanged += membershipListBox_SelectionChanged;
            membershipListBox.Loaded += membershipListBox_Loaded;

            CommandBindings.Add(new CommandBinding(NavigationCommands.BrowseHome, GoHomeExecuted, CommandCanExecute));
            CommandBindings.Add(new CommandBinding(NavigationCommands.BrowseBack, GoHomeExecuted, CommandCanExecute));
        }
 public UserViewModel Clone()
 {
     var clone = new UserViewModel();
     clone.UserName = UserName;
     clone.Description = Description;
     foreach (Group group in _user.GroupMembership) {
         clone.AddGroupMembership(new GroupViewModel(group));
     }
     return clone;
 }
 public void RestoreState(UserViewModel model)
 {
     if (model != null) {
         UserName = model.UserName;
         Description = model.Description;
         _user.GroupMembership.Clear();
         foreach (Group group in model._user.GroupMembership) {
             AddGroupMembership(new GroupViewModel(group));
         }
     }
 }