title: WPF Custom Control Dependency Property setter not getting called?
body: <p>I have created a custom control CustomTextBox inherited from TextBox class. I have created a dependency property named CustomTextProperty. </p>
  
  <p>I have binded this DP with my Viewmodel property.</p>
  
  <p>While Registering the DP i have given the property change callback but it is only get called one time when my control gets the binded data initially when my xaml loads.</p>
  
  <p>When i try to set my control from view the binded VM property setter does not gets called and also the propertychangecallback not gets fired.</p>
  
  <p>Please help!!</p>
  
  <p>Code snipet below:</p>
  
  <p>My Custom control</p>
  
  <pre><code>class CustomTextBox : TextBox
  {
    public static readonly DependencyProperty CustomTextProperty = DependencyProperty.Register("CustomText",
                                                                 typeof(string), typeof(CustomTextBox),
                                                                 new FrameworkPropertyMetadata("CustomTextBox",
                                                                 FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
                                                                 new PropertyChangedCallback(OnCustomPropertyChange)));
  
   public string CustomText
   {
     get { return (string)GetValue(CustomTextProperty); }
     set { SetValue(CustomTextProperty, value); }
   }
  
   private static void OnCustomPropertyChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
   {
     // This is Demo Application.
     // Code to be done Later...
   }
  }
  </code></pre>
  
  <p>My View Model:</p>
  
  <pre><code>public class ViewModel : INotifyPropertyChanged
  {
   private string textForTextBox;
  
   public string TextForCustomTextBox
   {
     get
     {
       return this.textForTextBox;
     }
     set
     {
       this.textForTextBox = value;
  
       this.OnPropertyChange("TextForCustomTextBox");
     }
   }
  
   public event PropertyChangedEventHandler PropertyChanged;
  
   public void OnPropertyChange(string name)
   {
     PropertyChangedEventHandler handler = PropertyChanged;
  
     if (handler != null)
     {
       handler(this, new PropertyChangedEventArgs(name));
     }
   }
  }
  </code></pre>
  
  <p>My Xaml Code with Binding:</p>
  
  <pre><code>&lt;custom:CustomTextBox x:Name="CustomTextBox" 
                                    CustomText="{Binding TextForCustomTextBox, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    Grid.Row="1" HorizontalAlignment="Center" Width="200" Height="50" /&gt;
  </code></pre>
  
  <p>My Code Behind to set DataContext:</p>
  
  <pre><code>// My View Constructor
  public View1()
  {
    InitializeComponent();
  
    this.DataContext = new ViewModel();
  }
  </code></pre>