title: DependencyProperty not working on CustomControl
body: <p>I'm trying to make a custom control, with some custom properties, however when attempting to Bind to the property it doesn't seem to work. </p>
  
  <p>Here is my Code Behind <strong>UserProfile.cs</strong></p>
  
  <pre><code>using System;
  using System.Windows;
  using System.Windows.Controls;
  
  namespace Controls
  {
      public class UserProfile : Control
      {
          static UserProfile()
          {
              DefaultStyleKeyProperty.OverrideMetadata(typeof(UserProfile),
                  new FrameworkPropertyMetadata(typeof(UserProfile)));
          }
  
          #region PhotoSize DP
          /// &lt;summary&gt;
          /// Gets or sets the Label which is displayed next to the field
          /// &lt;/summary&gt;
          public Double PhotoSize
          {
              get { return (Double)GetValue(PhotoSizeProperty); }
              set { SetValue(PhotoSizeProperty, value); }
          }
          /// &lt;summary&gt;
          /// Identified the Label dependency property
          /// &lt;/summary&gt;
          public static readonly DependencyProperty PhotoSizeProperty =
              DependencyProperty.Register("PhotoSize", typeof(Double),
                typeof(UserProfile), null);
          #endregion
      }
  }
  </code></pre>
  
  <p><strong>XAML - Generic.xaml</strong></p>
  
  <pre><code>&lt;Style TargetType="{x:Type local:UserProfile}"&gt;
          &lt;Setter Property="DataContext" Value="{x:Type local:UserProfile}" /&gt;
          &lt;Setter Property="Foreground" Value="White" /&gt;
          &lt;Setter Property="FontSize" Value="16" /&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="{x:Type local:UserProfile}"&gt;
                      &lt;Grid x:Name="circleGrid" Width="{Binding PhotoSize}"&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition Height="{Binding Path=ActualWidth, ElementName=circleGrid}" /&gt;
                              &lt;RowDefinition /&gt;
                              &lt;RowDefinition /&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;Border x:Name="circleBorder"
                                  Grid.Row="0"
                                  CornerRadius="{Binding Path=ActualWidth, ElementName=circleGrid}"
                                  Width="{Binding Path=ActualWidth, ElementName=circleGrid}"
                                  Height="{Binding Path=ActualWidth, ElementName=circleGrid}"
                                  BorderBrush="White"
                                  BorderThickness="3"&gt;
                              &lt;Border.Background&gt;
                                  &lt;ImageBrush ImageSource="D:\Users\Martyn Ball\Pictures\11061728_10153409797331063_2946862347621203654_o.jpg" Stretch="UniformToFill" /&gt;
                              &lt;/Border.Background&gt;
                          &lt;/Border&gt;
  
                          &lt;WrapPanel Grid.Row="1" HorizontalAlignment="Center"&gt;
                              &lt;TextBlock x:Name="firstName"
                                         FontWeight="Bold"
                                         Foreground="{TemplateBinding Foreground}"
                                         Text="Martyn" /&gt;
                              &lt;TextBlock Text=" "/&gt;
                              &lt;TextBlock x:Name="lastName"
                                         FontWeight="Normal"
                                         Foreground="{TemplateBinding Foreground}"
                                         Text="Ball" /&gt;
                          &lt;/WrapPanel&gt;
  
                          &lt;WrapPanel Grid.Row="2"&gt;
                              &lt;WrapPanel Margin="5"&gt;
                                  &lt;TextBlock x:Name="imageDifference" Text="" /&gt;
                                  &lt;TextBlock Text="56" /&gt;
                              &lt;/WrapPanel&gt;
                              &lt;WrapPanel Margin="5"&gt;
                                  &lt;TextBlock x:Name="earningsDifference" Text="£" /&gt;
                                  &lt;TextBlock Text="£50.50" /&gt;
                              &lt;/WrapPanel&gt;
                          &lt;/WrapPanel&gt;
                      &lt;/Grid&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
    <p>BindingExpression path error: 'PhotoSize' property not found on
    'object' ''RuntimeType' (HashCode=19976800)'.
    BindingExpression:Path=PhotoSize; DataItem='RuntimeType'
    (HashCode=19976800); target element is 'Grid' (Name=''); target
    property is 'Width' (type 'Double')</p>
  </blockquote>