/// <summary>
        /// Handles changes to the FormatValidationHandler property.
        /// </summary>
        /// <param name="d">
        /// The <see cref="DependencyObject"/> on which
        /// the property has changed value.
        /// </param>
        /// <param name="e">
        /// Event data that is issued by any event that
        /// tracks changes to the effective value of this property.
        /// </param>
        private static void OnFormatValidationHandlerChanged(
            DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextBox     textBox     = d as TextBox;
            PasswordBox passwordBox = d as PasswordBox;

            if (textBox != null)
            {
                TextBoxFormatValidationHandler oldFormatValidationHandler = (TextBoxFormatValidationHandler)e.OldValue;
                TextBoxFormatValidationHandler newFormatValidationHandler = (TextBoxFormatValidationHandler)textBox.GetValue(FormatValidationHandlerProperty);

                if (oldFormatValidationHandler != null)
                {
                    oldFormatValidationHandler.Detach();
                }

                newFormatValidationHandler.Attach(textBox);
            }
            else if (passwordBox != null)
            {
                PasswordBoxFormatValidationHandler oldFormatValidationHandler = (PasswordBoxFormatValidationHandler)e.OldValue;
                PasswordBoxFormatValidationHandler newFormatValidationHandler = (PasswordBoxFormatValidationHandler)passwordBox.GetValue(FormatValidationHandlerProperty);

                if (oldFormatValidationHandler != null)
                {
                    oldFormatValidationHandler.Detach();
                }

                newFormatValidationHandler.Attach(passwordBox);
            }
        }
        private static void SetupAndValidate(DependencyObject dependencyObject)
        {
            //if (DesignMode.DesignModeEnabled)
            //{
            //    return;
            //}

            TextBox     textBox     = dependencyObject as TextBox;
            PasswordBox passwordBox = dependencyObject as PasswordBox;

            if (textBox != null)
            {
                TextBoxFormatValidationHandler handler;

                if ((handler = GetFormatValidationHandler(textBox) as TextBoxFormatValidationHandler) == null)
                {
                    handler = new TextBoxFormatValidationHandler();
                    SetFormatValidationHandler(textBox, handler);
                }
                else
                {
                    handler.Validate();
                }
            }
            else if (passwordBox != null)
            {
                PasswordBoxFormatValidationHandler handler;

                if ((handler = GetFormatValidationHandler(passwordBox) as PasswordBoxFormatValidationHandler) == null)
                {
                    handler = new PasswordBoxFormatValidationHandler();
                    SetFormatValidationHandler(passwordBox, handler);
                }
                else
                {
                    handler.Validate();
                }
            }
        }