title: Custom UserControl property not being set via XAML DataBinding in Silverlight 4
body: <p>I have a custom user control called GoalProgressControl. Another user control contains GoalProgressControl and sets its GoalName attribute via databinding in XAML. However, the GoalName property is never set. When I check it in debug mode GoalName remains "null" for the control's lifetime.</p>
  
  <p>How do I set the GoalName property? Is there something I am doing incorrectly?</p>
  
  <p>I am using .NET Framework 4 and Silverlight 4. I am relatively new to XAML and Silverlight so any help would be greatly appreciated.</p>
  
  <p>I have attempted to change GoalProgressControl.GoalName into a POCO property but this causes a Silverlight error, and my reading leads me to believe that databound properties should be of type DependencyProperty. I've also simplified my code to just focus on the GoalName property (the code is below) with no success.</p>
  
  <p>Here is GoalProgressControl.xaml:</p>
  
  <pre><code>&lt;UserControl x:Class="GoalView.GoalProgressControl"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  DataContext="{Binding RelativeSource={RelativeSource Self}}"
  Height="100"&gt;
  
  &lt;Border Margin="5" Padding="5" BorderBrush="#999" BorderThickness="1"&gt;
      &lt;TextBlock Text="{Binding GoalName}"/&gt;
  &lt;/Border&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>GoalProgressControl.xaml.cs:</p>
  
  <pre><code>public partial class GoalProgressControl : UserControl, INotifyPropertyChanged
  {
  
      public GoalProgressControl()
      {
          InitializeComponent();
      }
  
  
      public event PropertyChangedEventHandler PropertyChanged;
      public void NotifyPropertyChanged(string propertyName)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  
      public static DependencyProperty GoalNameProperty = DependencyProperty.Register("GoalName", typeof(string), typeof(GoalProgressControl), null);
      public string GoalName
      {
          get
          {
              return (String)GetValue(GoalProgressControl.GoalNameProperty);
          }
          set
          {
              base.SetValue(GoalProgressControl.GoalNameProperty, value);
              NotifyPropertyChanged("GoalName");
          }
      }
  }
  </code></pre>
  
  <p>I've placed GoalProgressControl on another page:</p>
  
  <pre><code>    &lt;Grid Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="5" Background="#eee" Height="200"&gt;
          &lt;Border BorderBrush="#999" BorderThickness="1" Background="White"&gt;
              &lt;StackPanel&gt;
                  &lt;hgc:SectionTitleBar x:Name="ttlGoals" Title="Personal Goals" ImageSource="../Images/check.png" Uri="/Pages/GoalPage.xaml" MoreVisibility="Visible" /&gt;
                  &lt;ItemsControl ItemsSource="{Binding Path=GoalItems}"&gt;
                      &lt;ItemsControl.ItemTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;!--TextBlock Text="{Binding Path=[Name]}"/--&gt;
                              &lt;goal:GoalProgressControl GoalName="{Binding Path=[Name]}"/&gt;
  
                          &lt;/DataTemplate&gt;
                      &lt;/ItemsControl.ItemTemplate&gt;
                  &lt;/ItemsControl&gt;
              &lt;/StackPanel&gt;
          &lt;/Border&gt;
      &lt;/Grid&gt;
  </code></pre>
  
  <p>Please note the commented out "TextBlock" item above. If I comment in the TextBlock and comment out the GoalProgressControl, the binding works correctly and the TextBlock shows the GoalName correctly. Also, if I replace the "GoalName" property above with a simple text string (ex "hello world"), the control renders correctly and "hello world" is shown on the control when it renders.</p>