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

MaskedTextBox Mask binding

Jun 26, 2012 at 7:01 PM
Edited Jun 26, 2012 at 7:32 PM

Hello! Is it possible to bind Mask somehow? I need to load Mask for MasketTextBox control from config file or DB

Coordinator
Jun 27, 2012 at 5:49 PM

Hi,

 

The MaskedTextBox.Mask property is a dependency property.  You should be able to bind to it.

Jun 27, 2012 at 8:13 PM

When I'm doing something like that: Mask="{Binding Path=SomeMask}" - I'm getting error: Mask cannot be null. Parameter name:MaskedTextProvider

Coordinator
Jun 27, 2012 at 8:50 PM

Can you show me the XAML of your application, or at least the XAML of the MaskedTextBox?  What is the DataContext of the MaskedTextBox?  What is the value in the "SomeMask" property?

Jun 27, 2012 at 9:09 PM

Probably it's because I'm using MVVM. Error(System.ArgumentNullException) appears only when view is activated. After that mask is successfully bonded

XAML:
<wpfx:MaskedTextBox  Name="TestTextBox1" Style="{StaticResource TextInput}" Mask="{Binding Path=TestMask}"/>

Model:
 public string TestMask
        {
            get
            {
                return "00"; //will be taken from DB
            }
        }

Jun 28, 2012 at 7:39 AM

FallbackValue in Binding solved my problem. Nebuleux, thank you very much