title: WPF usercontrol binding to object don't work
body: <p>I have a problem with binding my usercontrol to object in mainwindow. I don't know what is wrong. </p>
  
  <p>I created custom control MyUserControl which has editable textbox</p>
  
  <p><strong>MyUsrControl.xaml</strong></p>
  
  <pre><code>&lt;UserControl x:Class="UserControlToObject.MyUsrControl"
               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"              
               mc:Ignorable="d" 
               d:DesignHeight="70" d:DesignWidth="200"&gt;    
      &lt;StackPanel Orientation="Horizontal"&gt;
          &lt;Label Grid.Row="0" Grid.Column="0" Margin="5"&gt;Name&lt;/Label&gt;            
          &lt;TextBox Grid.Row="0" Grid.Column="1" Margin="5" Name="tbxName"&gt;&lt;/TextBox&gt;
      &lt;/StackPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Next I defined DP to allow modify this textbox outside countrol</p>
  
  <p><strong>MyUsrControl.xaml.cs</strong></p>
  
  <pre><code>namespace UserControlToObject
  {
      public partial class MyUsrControl : UserControl
      {
          public static readonly DependencyProperty EmpNameProperty = DependencyProperty.Register("EmpNameProperty", typeof(string), typeof(MyUsrControl),           
                                 new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, EmpNamePropertyChanged));
  
          public string EmpName
          {
              get
              {
                  return (string)GetValue(EmpNameProperty);
              }
              set
              {
                  SetValue(EmpNameProperty, value);
              }
          }
  
          public MyUsrControl()
          {
              InitializeComponent();            
          }
  
          static void EmpNamePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
          {
              MyUsrControl x = (MyUsrControl)sender;
              x.tbxName.Text = (string)e.NewValue;
          }
      }
  }
  </code></pre>
  
  <p>Next, I defined Employee class - properties of object of this class will be displayed on user control </p>
  
  <pre><code>namespace UserControlToObject
  {
      /// &lt;summary&gt;
      /// Employee class
      /// &lt;/summary&gt;
      class Employee : INotifyPropertyChanged
      {
          string m_name, m_surname;
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          /// &lt;summary&gt;
          /// Employee name property
          /// &lt;/summary&gt;
          public string Name
          {
              get { return m_name; }
              set
              {
                  m_name = value;
                  OnPropertyChanged("Name");
              }
          }
  
          /// &lt;summary&gt;
          /// Employee surname property
          /// &lt;/summary&gt;
          public string Surname
          {
              get { return m_surname; }
              set
              {
                  m_surname = value;
                  OnPropertyChanged("Surname");
              }
          }
  
          public Employee()
          {
              m_name = "unknown name";
              m_surname = "unknown surname";
          }
  
          public Employee(string name, string surname)
          {
              m_name = name;
              m_surname = surname;
          }    
  
          protected void OnPropertyChanged(string name)
          {
              PropertyChangedEventHandler handler = PropertyChanged;
  
              if (handler != null)
              {
                  handler(this, new PropertyChangedEventArgs(name));
              }
          }
  
      }
  </code></pre>
  
  <p>And finally MainWindow.xaml</p>
  
  <pre><code>&lt;Window x:Name="myApp" x:Class="UserControlToObject.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:local="clr-namespace:UserControlToObject"        
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;StackPanel&gt;
          &lt;local:MyUsrControl x:Name="ucEmp" EmpName="{Binding Name}"&gt;&lt;/local:MyUsrControl&gt;
          &lt;Label Content="{Binding ElementName=ucEmp, Path=EmpName}"&gt;&lt;/Label&gt;
  
      &lt;/StackPanel&gt;
  &lt;/Window
  </code></pre>
  
  <p>></p>
  
  <p>MainWindow.xaml.cs</p>
  
  <pre><code>namespace UserControlToObject
  {
      public partial class MainWindow : Window
      {
          Employee anEmployee;
  
          public MainWindow()
          {
              InitializeComponent();
              anEmployee = new Employee("John", "Wayne");
  
              this.DataContext = anEmployee;         
          }
  
      }
  </code></pre>
  
  <p>}</p>
  
  <p>This line don't work (error saying that I can set binding only on DependencyProperty... of DependencyObject):</p>
  
  <pre><code>&lt;local:MyUsrControl x:Name="ucEmp" EmpName="{Binding Name}"&gt;&lt;/local:MyUsrControl&gt;
  </code></pre>
  
  <p>Those settings below works, so I think that's problem with my Employee class (sth is missing ?) </p>
  
  <pre><code>&lt;local:MyUsrControl x:Name="ucEmp" EmpName="John"&gt;&lt;/local:MyUsrControl&gt; --&gt; set EmpName ok
  &lt;Label Content="{Binding ElementName=ucEmp, Path=EmpName}"&gt;&lt;/Label&gt; --&gt; get EmpName ok
  </code></pre>
  
  <p>I've no idea whot is wrong, so will be very greatfull for help
              </p>
  
  <p>I did the same but binding TextBox instead of user control and was no problem. 
  TextBox.Text is dependency property same as my Employee.EmpName</p>