/// <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; }
/// <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); } }