/// <summary>
 /// Occurs when the value of the Password property changes.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="routedEventArgs">An EventArgs that contains no event data.</param>
 private void OnPasswordBoxPasswordChanged(object sender, RoutedEventArgs routedEventArgs)
 {
     // When the password box has been loaded and is taking changes from the user, we will copy the changes out of the password box and into the data context
     // that was associated with the item.  This isn't, strictly speaking, MVVM, but its as close as we're going to get without a dependency property on the
     // 'SecurePassword' property.  This is understandable for security reasons.
     if (this.IsLoaded)
     {
         PasswordBox      passwordBox       = sender as PasswordBox;
         DomainCredential domainCredentials = passwordBox.DataContext as DomainCredential;
         domainCredentials.SecurePassword = passwordBox.SecurePassword;
     }
 }
        /// <summary>
        /// Occurs when this FrameworkElement is initialized.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="eventArgs">An EventArgs that contains no event data.</param>
        void OnPasswordBoxInitialized(Object sender, EventArgs eventArgs)
        {
            // Since we don't have access to the password (as it is secured inside the SecureString object), we will fill in the password box with a dummy set of
            // characters that is the same length as the password.  Since the box encodes the characters anyway, it doesn't 'really matter what we initialize the
            // box with so long as it has the proper number of characters.
            PasswordBox      passwordBox       = sender as PasswordBox;
            DomainCredential domainCredentials = passwordBox.DataContext as DomainCredential;

            passwordBox.Password = new String('*', domainCredentials.SecurePassword.Length);

            // We assume that all passwords are going to be overwritten since we can't really edit them like a visible string.
            passwordBox.SelectAll();
        }
        /// <summary>
        /// Determines whether the specified Object is equal to the current Object.
        /// </summary>
        /// <param name="obj">The object to compare with the current object.</param>
        /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            // Only the domain and user name are significant for comparing two objects.
            DomainCredential domainCredential = obj as DomainCredential;

            if (domainCredential != null)
            {
                return(this.DomainUserName == domainCredential.DomainUserName);
            }

            // There is no comparing this object to any other type.
            return(false);
        }