Home / Community & Support / Knowledge Base / RadControls for WPF / MaskedTextBox / MaskedTextBox - DataBinding with StandardMask

MaskedTextBox - DataBinding with StandardMask

Article Info

Rating: Not rated

Article information

Article relates to

 MaskedTextBox

Created by

 Boryana Miloshevska

Last modified

 December, 12, 2009

Last modified by

 



MaskedTextBox - DataBinding with StandardMask

This article demonstrates the usage of different Bindings in RadMaskedTextBox with Standard mask.
At fires lets add some classes that will represent the data we want to show in the maskedtextbox:

1.Add the following class:
public class DataClass : INotifyPropertyChanged
   {
       private int num;
       public int Num
       {
           get
           {
               return num;
           }
           set
           {
               if (this.num != value)
               {
                   this.num = value;
                   this.OnPropertyChanged("Num");
               }
           }
       }
 
       public event PropertyChangedEventHandler PropertyChanged;
 
       protected virtual void OnPropertyChanged(string propertyName)
       {
           if (this.PropertyChanged != null)
           {
               this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
           }
       }
 
   }

2.After that add some DataSource class:
public  class DataSource
    {
        public  ObservableCollection<DataClass> data;
        public  DataSource()
        {
            data = GetDataSource();
        }
 
        public  ObservableCollection<DataClass> GetDataSource()
        {
            data = new ObservableCollection<DataClass>();
            data.Add(new DataClass(){Num = 23});
            return data;
        }
    }

3.And finally set the current DataContext:
DataClass  ds = new DataClass() { Num = 23 };
       
this.DataContext = ds;

4.In XAML you can set different value bindings:
<telerik:RadMaskedTextBox MaskType="Standard"  Mask="#####"
                                  Value="{Binding Num, Mode=TwoWay}"/>
<telerik:RadMaskedTextBox MaskType="Standard"  Mask="#####"
                                  Value="{Binding Num}"/>

That is all you have to do in order to have data bound RadMaskedTextBox.

Comments

There are no comments yet.
If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.