title: How to create a Dependency Property for Binding
body: <p>I'm working on a "simple" case. I like to create a new custom control which implements a DependencyProperty. In the next step I like to create a binding for updating the properties in both directions. I've builded a simple sample for this case, but the binding doesn't seem to work. I've found a way for updating the DPControl's property by using the FrameworkPropertyMetadata, but I don't know whether it's also a good idea to use the OnPropertyChanged event.</p>
  
  <p>HERE is my sample project:</p>
  
  <p>My control contains simply a Label</p>
  
  <pre><code>&lt;UserControl x:Class="WPF_MVVM_ListBoxMultiSelection.DPControl"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               xmlns:local="clr-namespace:WPF_MVVM_ListBoxMultiSelection"
               mc:Ignorable="d" Height="84.062" Width="159.641"&gt;
      &lt;Grid Margin="0,0,229,268"&gt;
          &lt;Label Content="TEST" x:Name="label" Margin="0,0,-221,-102"/&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>and implement a custom dependency property. Currently, I have also implemented the PropertyChanged method for the FramePropertyMetadata and set in this method the label's content, but I like to get it work in both directions.</p>
  
  <pre><code>public partial class DPControl : UserControl
  {
      public DPControl()
      {
          InitializeComponent();
      }
  
      public string MyCustomLabelContent
      {
          get { return (string)GetValue(MyCustomLabelContentProperty);}
          set
          {
              SetValue(MyCustomLabelContentProperty, value);
          }
      }
  
      private static void OnMyCustomLabelContentPropertyChanged(DependencyObject source,
      DependencyPropertyChangedEventArgs e)
      {
          DPControl control = (DPControl)source;
          control.label.Content = e.NewValue;
      }
  
      public static readonly DependencyProperty MyCustomLabelContentProperty = DependencyProperty.Register(
            "MyCustomLabelContent",
            typeof(string),
            typeof(DPControl),
            new FrameworkPropertyMetadata(null,
                OnMyCustomLabelContentPropertyChanged
            )
          );
  </code></pre>
  
  <p>I use this control simply in a Window by:</p>
  
  <pre><code>&lt;local:DPControl MyCustomLabelContent="{Binding MyLabelContent, Mode=TwoWay}" Margin="72,201,286,34"/&gt;
  </code></pre>
  
  <p><code>MyLabelContent</code> is a property in the ViewModel, which has implemented also the INotifyPropertyChanged interface.</p>
  
  <pre><code>public class ViewModel_MainWindow:NotifyPropertyChanged
  {
  
      private string _myLabelContent;
  
      public string MyLabelContent
      {
          get { return _myLabelContent; }
          set { _myLabelContent = value;
              RaisePropertyChanged();
          }
      }...
  </code></pre>
  
  <p>So how can I get it work: Using the binding feature with my new control on custom properties.</p>