title: WPF Set user control dependency properties
body: <p>Below a piece of my user control:</p>
  
  <pre><code>&lt;UserControl x:Class="WpfApplication1.Controls.CircularProgressBar"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               Background="Transparent"
               Height="{Binding ControlHeightProperty}"
               Width="{Binding ControlWidthProperty}"&gt;
  
    &lt;UserControl.Resources&gt;
      &lt;SolidColorBrush x:Key="progressCirclesColor" Color="#FF2E6187" /&gt;
    &lt;/UserControl.Resources&gt;
  
      &lt;Viewbox Width="{Binding ControlWidthProperty}" Height="{Binding ControlHeightProperty}" HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
      &lt;!-- other objects --&gt;
      &lt;/Viewbox&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>and its code-behind with my dependency properties:</p>
  
  <pre><code>public partial class CircularProgressBar
  {
      public static readonly DependencyProperty ControlHeightProperty =
          DependencyProperty.Register("ControlHeight", typeof(int), typeof(CircularProgressBar), new UIPropertyMetadata(45));
  
      public static readonly DependencyProperty ControlWidthProperty =
          DependencyProperty.Register("ControlWidth", typeof(int), typeof(CircularProgressBar), new UIPropertyMetadata(45));
  
      public int ControlHeight
      {
          get { return (int)GetValue(ControlHeightProperty); }
          set { SetValue(ControlHeightProperty, value); }
      }
  
      public int ControlWidth
      {
          get { return (int)GetValue(ControlWidthProperty); }
          set { SetValue(ControlWidthProperty, value); }
      }
  }
  </code></pre>
  
  <p>Then from my wpf main window:</p>
  
  <p></p>
  
  <pre><code>    &lt;ctr:CircularProgressBar x:Name="progressBar" Grid.ZIndex="3"                             
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           ControlHeight="100"
                           ControlWidth="100"/&gt;   
  </code></pre>
  
  <p></p>
  
  <p>What I am trying to do is set width and height for my user control from my main window. In above example I am trying to set user control height and width to 100 through dependency properties ControlHeight and ControlWidth respectively.</p>
  
  <p>If from my main windows ControlHeight and ControlWidth is not specified, I want user control height and width take as default value of 45.</p>
  
  <p>But above example is not working for me. What am I doing wrong?</p>
  
  <p><strong>UPDATE WORKING</strong>:
  As Clemens suggested, I have changed the code into the following:</p>
  
  <pre><code>&lt;UserControl x:Class="WpfApplication1.Controls.CircularProgressBar"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               Background="Transparent"&gt;
  
    &lt;UserControl.Resources&gt;
      &lt;SolidColorBrush x:Key="progressCirclesColor" Color="#FF2E6187" /&gt;
    &lt;/UserControl.Resources&gt;
  
      &lt;Viewbox HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
      &lt;!-- other objects --&gt;
      &lt;/Viewbox&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>In code-behind dependency properties ControlHeightProperty and ControlWidthProperty are not needed. </p>
  
  <p>Finally in my wpf window, setting typical height and width properties are enough:</p>
  
  <p></p>
  
  <pre><code>    &lt;ctr:CircularProgressBar x:Name="progressBar" Grid.ZIndex="3"                             
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Height="100"
                           Width="100"/&gt;   
  </code></pre>
  
  <p></p>