// Remove a user in the FlickrLoginAccountName list. // By using this method, we trigger the property changed event and set IsChanged. public bool RemoveFlickrSearchAccountName(User user) { int index = FlickrSearchAccountList.ToList <User>().FindIndex(x => x.UserName == user.UserName); if (index < 0) { MessageBox.Show("Unexpected error. The user '" + user.UserName + "' is not found."); return(false); } else { FlickrSearchAccountList.RemoveAt(index); OnPropertyChanged("FlickrSearchAccountList"); IsChanged = true; FlickrSearchAccountList.ResetBindings(); if (FlickrSearchAccountList.Count == 0) { FlickrSearchAccountName = ""; } else if (index < FlickrSearchAccountList.Count) { FlickrSearchAccountName = FlickrSearchAccountList[index].UserName; } else { FlickrSearchAccountName = FlickrSearchAccountList[index - 1].UserName; } UpdateEnabledProperties(); return(true); } }
// Add a new user or replace an existing user to the FlickrLoginAccountName list. // Keep the list in sorted order by name. public void AddReplaceFlickrSearchAccountName(User newUser) { // Find where to insert in the list. // It's a small list, don't bother with binary search int index = 0; while (index < FlickrSearchAccountList.Count) { int compare = String.Compare(FlickrSearchAccountList[index].UserName, newUser.UserName, StringComparison.OrdinalIgnoreCase); if (compare == 0) { // Found matching name, replace it FlickrSearchAccountList[index] = newUser; break; } else if (compare > 0) { // Found name beyond the new user name, so insert before here. FlickrSearchAccountList.Insert(index, newUser); break; } index++; } if (index >= FlickrSearchAccountList.Count) { // NewUser is beyond end of list. Add to the end. FlickrSearchAccountList.Add(newUser); } OnPropertyChanged("FlickrSearchAccountList"); IsChanged = true; FlickrSearchAccountList.ResetBindings(); FlickrSearchAccountName = newUser.UserName; UpdateEnabledProperties(); }