MaskedTextBox Text binding

Apr 28, 2011 at 3:23 PM

My question is Text binding, it is not working for me.

My class implements INotifyPropertyChanged and other controls bound to this class works fine. 

   <tk:MaskedTextBox HorizontalAlignment="Left" 
       Mask="00/00/0000" Width="150" Height="25"
        IncludeLiterals="True" Text="{Binding Path=ResponseValue, Mode=TwoWay}"  />

What is missing here?

Thanks 

Apr 28, 2011 at 4:58 PM

Do not bind to the Text property.  Instead bind to the Value property.

Apr 28, 2011 at 5:04 PM

That means Text property is not a dependency property in MaskedTextBox ? 

Apr 28, 2011 at 5:12 PM

The Text property is a DP, but it is not the property to use for binding the source value.  The text property is used to get the formatted text from the MastTextBox.  The Value property is used to bind the source value to.  Please review the documentation: http://wpftoolkit.codeplex.com/wikipage?title=MaskedTextBox&referringTitle=Documentation

Apr 28, 2011 at 6:24 PM

OK Thanks , the naming confused me ! Text is DP in Textbox and TextBlock and it supports binding. Now it is not supporting binding in MaskedTextBox but Value does. Ok !

Apr 28, 2011 at 11:51 PM

The Text property does support binding, but it is not the property to bind your source property to.  This is because your source value may be a different data type than string, which Microsoft's controls only support string.  The convention in the Extended WPF Toolkit, is that most controls have a Value property to bind your source value to.

Apr 5, 2012 at 3:36 PM

Hi, i have the same problem with binding a Datetime to the Text property. I solve the problem setting the StringFormat in the binding.

<my:MaskedTextBox Height="23" TextAlignment="Center" HorizontalAlignment="Left" Margin="14,83,0,0"
                          Name="maskedTextBoxDataEmissao" VerticalAlignment="Top" Width="140" Mask="99/99/9999"
                          Text="{Binding ElementName=ContaAReceberUc,Path=ContaAReceber.DataEmissao, StringFormat=dd/MM/yyyy, Mode=TwoWay}"/>