ToDisplayString() public method

Returns a formatted string based on the mask, honoring only the PasswordChar property. prompt character and literals are always included. This is the text to be shown in a control when it has the focus.
public ToDisplayString ( ) : string
return string
Ejemplo n.º 1
1
 private static object CoerceText(DependencyObject d, object value)
 {
     MaskedTextBox textBox = (MaskedTextBox)d;
     MaskedTextProvider maskProvider = new MaskedTextProvider(textBox.Mask);
     maskProvider.Set((string)value);
     return maskProvider.ToDisplayString();            
 }
Ejemplo n.º 2
0
 //force the text of the control to use the mask
 private static object ForceText(DependencyObject sender, object value)
 {
     MaskedTextBox textBox = (MaskedTextBox) sender;
     if (textBox.Mask != null)
     {
         MaskedTextProvider provider = new MaskedTextProvider(textBox.Mask);
         provider.Set((string) value);
         return provider.ToDisplayString();
     }
     else
     {
         return value;
     }
 }
Ejemplo n.º 3
0
        private void MaskedTextBoxLoaded(object sender, RoutedEventArgs e)
        {
            _provider = new MaskedTextProvider(!string.IsNullOrEmpty(InputMask) ? InputMask : " ", CultureInfo.CurrentCulture);

            _provider.Set(String.IsNullOrWhiteSpace(UnmaskedText) ? String.Empty : UnmaskedText);

            _provider.PromptChar = PromptChar;
            Text = _provider.ToDisplayString();

            DependencyPropertyDescriptor textProp = DependencyPropertyDescriptor.FromProperty(TextProperty,
                                                                                              typeof(MaskedTextBox));
            if (textProp != null)
            {
                textProp.AddValueChanged(this, (s, args) => UpdateText());
            }
            DataObject.AddPastingHandler(this, Pasting);
        }
Ejemplo n.º 4
0
        private void RefreshText(MaskedTextProvider maskProvider, int pos)
        { 
            // Refresh string.            
            this.Text = maskProvider.ToDisplayString();

            // Position cursor.
            this.SelectionStart = pos;
        }
Ejemplo n.º 5
0
        private void UpdateText(MaskedTextProvider provider, int position)
        {
            if (provider == null)
                throw new ArgumentNullException("MaskedTextProvider", "Mask cannot be null.");

            Text = provider.ToDisplayString();

            SelectionStart = position;
        }
 //refreshes the text of the textbox
 private void RefreshText(MaskedTextProvider provider, int position)
 {
     if (provider != null)
     {
         Text = provider.ToDisplayString();
         SelectionStart = position;
     }
 }
Ejemplo n.º 7
0
		public void ToDisplayString ()
		{
			MaskedTextProvider mtp;

			mtp = new MaskedTextProvider ("##-##");
			mtp.PasswordChar = '*';
			Assert.AreEqual ("__-__", mtp.ToDisplayString ());

			mtp.Add ("666");
			Assert.AreEqual ("**-*_", mtp.ToDisplayString ());
		}
Ejemplo n.º 8
0
 private string GetMaskedInput(string name, string primaryFieldFormat)
 {
     var provider = new MaskedTextProvider(primaryFieldFormat, CultureInfo.CurrentCulture);
     provider.Set(name);
     return provider.ToDisplayString();
 }
Ejemplo n.º 9
0
        //refreshes the text of the textbox
        protected void RefreshText(MaskedTextProvider provider, int position)
        {
            if (provider == null) return;

            Text = provider.ToDisplayString();
            SelectionStart = position;
        }
Ejemplo n.º 10
0
        protected virtual object ForceText(object value)
        {
            if (Mask != null)
            {
                var provider = new MaskedTextProvider(Mask) { PromptChar = PromptChar};
                if(value != null)
                    provider.Set((string)value);
                return provider.ToDisplayString();
            }

            return value;
        }
Ejemplo n.º 11
0
 public static string GetMaskedString(string mask, string input)
 {
     MaskedTextProvider provider = new MaskedTextProvider(mask);
     provider.Add(input);
     return provider.ToDisplayString();
 }