/// <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);
            }
        }
Beispiel #2
0
        /// <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)
        {
            TextBoxFormatValidationHandler oldFormatValidationHandler = (TextBoxFormatValidationHandler)e.OldValue;
            TextBoxFormatValidationHandler newFormatValidationHandler = (TextBoxFormatValidationHandler)d.GetValue(FormatValidationHandlerProperty);

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

            newFormatValidationHandler.Attach((TextBox)d);
        }