コード例 #1
0
        // Remove a user in the FlickrLoginAccountName list.
        // By using this method, we trigger the property changed event and set IsChanged.
        public bool RemoveFlickrLoginAccountName(User user)
        {
            int index = FlickrLoginAccountList.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
            {
                FlickrLoginAccountList.RemoveAt(index);
                OnPropertyChanged("FlickrLoginAccountList");
                IsChanged = true;
                FlickrLoginAccountList.ResetBindings();
                if (FlickrLoginAccountList.Count == 0)
                {
                    FlickrLoginAccountName = "";
                }
                else if (index < FlickrLoginAccountList.Count)
                {
                    FlickrLoginAccountName = FlickrLoginAccountList[index].UserName;
                }
                else
                {
                    FlickrLoginAccountName = FlickrLoginAccountList[index - 1].UserName;
                }
                UpdateEnabledProperties();
                return(true);
            }
        }
コード例 #2
0
        // Add a new user or replace an existing user to the FlickrLoginAccountName list.
        // By using this method, we trigger the property changed event and set IsChanged.
        // If the user replaces an element in the list directly, these don't occur.
        public void AddReplaceFlickrLoginAccountName(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 < FlickrLoginAccountList.Count)
            {
                int compare = String.Compare(FlickrLoginAccountList[index].UserName, newUser.UserName, StringComparison.OrdinalIgnoreCase);
                if (compare == 0)
                {
                    // Found matching name, replace it
                    FlickrLoginAccountList[index] = newUser;
                    break;
                }
                else if (compare > 0)
                {
                    // Found name beyond the new user name, so insert before here.
                    FlickrLoginAccountList.Insert(index, newUser);
                    break;
                }
                index++;
            }
            if (index >= FlickrLoginAccountList.Count)
            {
                // NewUser is beyond end of list. Add to the end.
                FlickrLoginAccountList.Add(newUser);
            }

            OnPropertyChanged("FlickrLoginAccountList");
            IsChanged = true;
            FlickrLoginAccountList.ResetBindings();
            FlickrLoginAccountName = newUser.UserName;
            UpdateEnabledProperties();
        }