This project has moved. For the latest updates, please go here.

IncludePrompt & IncludeLiterals on MaskedTextBox

Mar 4, 2011 at 10:32 PM

By default IncludePrompt & IncludeLiterals are set to False. If so, why does Value of the textbox return "(   ) ___-____"? 

I've tried multiple scenarios to have the Value return as an empty string, but no avail.

Any ideas?


Mar 5, 2011 at 12:07 AM

Actually IncludeLiterals is true by default.  So if you do not want to the Value to include the literals you must set IncludeLiterals to false.  Also don't get confused by what the textbox shows.  The MaskedTextBox.Text property can be different than MaskedTextBox.Value.

Mar 5, 2011 at 3:35 AM

This is the code I have, but it's still returning the Literals:


 <my:MaskedTextBox Name="txtMobilePhone" Width="200" Mask="(000) 000-0000" TabIndex="12" IncludeLiterals="False" />

 private string MobilePhone       
          get { return (string)txtMobilePhone.Value; }            
          set { txtMobilePhone.Value = value; }       

.Value returns: (___) ___-____

See anywhere what I'm doing wrong?

Mar 5, 2011 at 4:40 PM

You should look for any code that is setting the Value.  I cannot duplicate the behavior you are describing.

        <extToolkit:MaskedTextBox x:Name="_txtMask" Mask="(000) 000-0000" IncludeLiterals="False" />
            <Button Click="Button_Click">Get Value</Button>
        private string MobilePhone
            get { return (string)_txtMask.Value; }
            set { _txtMask.Value = value; }

        private void Button_Click(object sender, RoutedEventArgs e)
            var value = MobilePhone;
I don't ever set the Value and it returns as NULL.  When I set the value to 5551234567 it still works as expected.
Mar 5, 2011 at 7:48 PM


After setting my previously saved values to NULL, all works great!

Thanks SO much for this Extended Toolkit!