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

MaskedTextBox - only value needed

Mar 15, 2012 at 1:23 PM
Edited Mar 15, 2012 at 1:23 PM

Hello guys,

I have a few questions. I develop simple WPF application on .net fw 3.5 sp1 and I use MVVM pattern.

1) Is there any change to get only value from MaskedTextBox?

I need only number without mask. I tried something, but without any result.

<ext:MaskedTextBox Name="txtTextBox" Grid.Row="0" Grid.Column="1" Mask="(000) \A\B\C 000-0000" Value="{Binding Path=MyTextBox}" />
I need to do something like this:
from this (123) ABC 321-1234 -> get this 1233211234

2) Is there something like FormatString in DecimalUpDown?

I'd like to use MaskedTextBox but customer wants to change number "1" to "01". In DecimalUpDown I can simulated with FormatString="00".

 <ext:DecimalUpDown FormatString="00" Increment="1" Maximum="99" Minimum="1" Width="250" TextAlignment="Left" Watermark="Enter Integer" />

Why I don't want to use DecimalUpDown?

Because I'd like to change mask on the fly.

 

Sorry for my bad english. 

Looking forward to a reply.

Pavel L.

Coordinator
Mar 16, 2012 at 3:18 PM

1) In order to have only the numbers from the MaskedTextBox, make sure you have set the "IncludeLiterals" and the "IncludePrompt" properties to "False".  You may set the "ValueType" property to type Int32 if you want the "Value" property to return an Int32 value.  Otherwise, the "Value" property will return a string value.  I don't know if this was intended, but your binding is "OneWay".  You should make it "TwoWay" if you want your "MyTextBox" to be updated.

 

2) Unfortunately, there is no such thing as FormatString on the MaskedTextBox or anything that could simulate that behavior.

 

Mar 22, 2012 at 7:19 AM

Thanks for your fast replay Nebuleux!

Yeah, whole problem was in default value of "IncludeLiterals". I expected that was false :)

And my default binding is really "TwoWay". I don't know how but its truth.

 

2) I used Converter and made from "1" this "01".

Have a nice day

and thanks once more time.