title: WPF binding user control with data in C# code
body: <p>I've create user control like this:</p>
  
  <pre><code>public partial class View
      {
          public View()
          {
              InitializeComponent();
          }
  
          public static DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(TeaserView) );
  
          public string Name
          {
              get { return (string)GetValue(NameProperty); }
              set { SetValue(NameProperty, value); }
          }
  
      }
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>&lt;UserControl x:Class="Controls.View"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Height="200" Width="164"&gt;
      &lt;Grid VerticalAlignment="Stretch"
            x:Name="Preview"&gt;
  
          &lt;Label Height="28"  Content="{Binding ElementName=Preview, Path=Name}" Background="LightYellow" x:Name="name" VerticalAlignment="Top" &gt;&lt;/Label&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>and use it in Window1 simply in XAML:</p>
  
  <pre><code>&lt;controls:View Height="200" Name="View1" Width="164" /&gt;
  </code></pre>
  
  <p>and I try set the Content in C# (Name property in this sample) but it does'n work, label's content is still empty. (All refereces, etc. are good) What's wrong?</p>