title: Custom Control Dependency Property Binding to Property
body: <p>Just playing around with different types of bindings and having a property binding a Dependency Property of my custom control to another property.</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;UserControl x:Class="BrickBreaker.Brick"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d"
  d:DesignHeight="20" d:DesignWidth="50"  &gt;
  &lt;Rectangle Width="50" Height="20" RadiusX="3" RadiusY="3" Stroke="Black" Fill="{Binding BrickFill, Mode=TwoWay}" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Code Behind:</p>
  
  <pre><code>public partial class Brick : UserControl
  {
      public Brick()
      {
          InitializeComponent();
  
      }
  
      public Brush BrickFill
      {
          get { return (Brush)GetValue(BrickFillProperty); }
          set { SetValue(BrickFillProperty, value); }
      }
  
      // Using a DependencyProperty as the backing store for BrickFill.  This enables animation, styling, binding, etc...
      public static readonly DependencyProperty BrickFillProperty =
          DependencyProperty.Register("BrickFill", typeof(Brush), typeof(Brick), null);
  
  
  
  }
  </code></pre>
  
  <p>Implemenation In MainWindow.xaml</p>
  
  <pre><code>&lt;UserControl x:Class="BrickBreaker.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:BrickBreaker="clr-namespace:BrickBreaker" mc:Ignorable="d"
  d:DesignHeight="300" d:DesignWidth="400"&gt;
  
  &lt;Grid x:Name="LayoutRoot" Background="White"&gt;
      &lt;BrickBreaker:Brick Margin="100,100,0,0" BrickFill="Azure"/&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>Basically I want to bind the Rectangles Fill Property to the Dependency Property in the code behind.</p>
  
  <p>Thanks.</p>
  
  <p>Steve</p>