/// <summary> /// Called when mask property is changed. /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { InputHelper.IsPropertyUpdate = true; MaskTextBox textBox = (MaskTextBox)d; InputHelper.IsPropertyUpdate = false; }
/// <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); } }