Exemplo n.º 1
0
        /// <summary>
        /// Use the mask to generate a new display string.
        /// </summary>
        /// <param name="maskProvider"></param>
        /// <param name="position"></param>
        private void RefreshText(MaskTextFormatter maskProvider, int position)
        {
            // Refresh string.
            this.Text = maskProvider.ToString();

            // Position cursor.
            this.SelectionStart = position;
        }
Exemplo n.º 2
0
        /// <summary>
        ///Force the text of the control to use the mask
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private static object ForceText(DependencyObject sender, object value)
        {
            MaskTextBox textBox = (MaskTextBox)sender;

            if (textBox.Mask != null && value != null)
            {
                MaskTextFormatter provider = new MaskTextFormatter(textBox.Mask);
                provider.Validate += delegate(char character)
                { return(textBox.IsValid(character)); };
                provider.Set((string)value);
                return(provider.ToString());
            }
            else
            {
                return(value);
            }
        }