/// <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);
            }
        }
示例#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);
        }
示例#3
0
        private static void SetupAndValidate(TextBox textBox)
        {
            //if (DesignMode.DesignModeEnabled)
            //{
            //    return;
            //}

            TextBoxFormatValidationHandler handler = null;

            if ((handler = GetFormatValidationHandler(textBox)) == null)
            {
                handler = new TextBoxFormatValidationHandler();
                SetFormatValidationHandler(textBox, handler);
            }
            else
            {
                handler.Validate();
            }
        }
        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();
                }
            }
        }
示例#5
0
 /// <summary>
 /// Sets the FormatValidationHandler property. This dependency property
 /// indicates the handler that checks the format in the TextBox.
 /// </summary>
 public static void SetFormatValidationHandler(DependencyObject d, TextBoxFormatValidationHandler value)
 {
     d.SetValue(FormatValidationHandlerProperty, value);
 }
        private static void SetupAndValidate(TextBox textBox)
        {
            //if (DesignMode.DesignModeEnabled)
            //{
            //    return;
            //}

            TextBoxFormatValidationHandler handler = null;

            if ((handler = GetFormatValidationHandler(textBox)) == null)
            {
                handler = new TextBoxFormatValidationHandler();
                SetFormatValidationHandler(textBox, handler);
            }
            else
            {
                handler.Validate();
            }
        }
 /// <summary>
 /// Sets the FormatValidationHandler property. This dependency property 
 /// indicates the handler that checks the format in the TextBox.
 /// </summary>
 public static void SetFormatValidationHandler(DependencyObject d, TextBoxFormatValidationHandler value)
 {
     d.SetValue(FormatValidationHandlerProperty, value);
 }
        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();
                }
            }
        }