title: WPF - How to bind to a UserControl property within a UserControl so that the child updates the parent?
body: <p>I am trying to create a basic colour change UserControl utilising my custom slider control, LabelSlider. I can get the colour to be set via code, however if I move the slider or enter text into the TextBox, it doesn't update the colour.</p>
  
  <p>LabelSlider XAML:</p>
  
  <pre><code>&lt;Slider x:Name="ucSlider" x:FieldModifier="private" Margin="{Binding SliderSpacing, FallbackValue=5, Converter={StaticResource DoubleToMargin}}" VerticalAlignment="Center" Grid.Column="1" Width="{Binding SliderWidth}" MaxWidth="{Binding SliderWidth}" FontFamily="Segoe UI" Value="{Binding Value, Mode=TwoWay}" SmallChange="1" Maximum="255"/&gt;
  &lt;TextBox x:Name="ucTextBox" x:FieldModifier="private" Text="{Binding Value, TargetNullValue=0, Mode=TwoWay}" Margin="{Binding TextBoxSpacing, FallbackValue=5, Converter={StaticResource DoubleToMargin}}" Grid.Column="2" PreviewKeyDown="LabelSlider_PreviewKeyDown" PreviewTextInput="LabelSlider_PreviewTextInput" MaxLength="3" Width="30" MaxWidth="30" FontFamily="Segoe UI" TextChanged="LabelSlider_TextChanged"/&gt;
  </code></pre>
  
  <p>LabelSlider Code Behind:</p>
  
  <pre><code>public int Value
  {
    get { return (int)GetValue(ValueProperty); }
    set { SetValue(ValueProperty, value); }
  }
  
  public static readonly DependencyProperty ValueProperty = DependencyProperty.Register
  (
    "Value",
    typeof(int),
    typeof(LabelSlider),
    new PropertyMetadata(null)
  );
  </code></pre>
  
  <p>ColourSelection XAML:</p>
  
  <pre><code>&lt;UserControl x:Class="Homuli.UserControls.ColourSelection"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           xmlns:local="clr-namespace:Homuli.UserControls"
           mc:Ignorable="d" 
           d:DesignHeight="300" d:DesignWidth="300" x:Name="colourSelection"&gt;
  &lt;StackPanel Margin="5,0,0,0" DataContext="{Binding ElementName=colourSelection}"&gt;
      &lt;local:LabelSlider Label="R" SliderSpacing="6" SliderWidth="100" Value="{Binding R, FallbackValue=255, TargetNullValue=0}" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,-4"/&gt;
      &lt;local:LabelSlider Label="G" SliderSpacing="5" SliderWidth="100" Value="{Binding G, FallbackValue=0, TargetNullValue=0}" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,-4"/&gt;
      &lt;local:LabelSlider Label="B" SliderSpacing="6" SliderWidth="100" Value="{Binding B, FallbackValue=0, TargetNullValue=0}" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,-4"/&gt;
          &lt;StackPanel Orientation="Horizontal"&gt;
              &lt;local:LabelTextBox Label="Hex" Spacing="15" TextBoxWidth="50" Text="{Binding Hex}" MaxLength="6" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center"/&gt;
              &lt;Rectangle Fill="{Binding Colour}" Height="26" Width="26" Margin="26,0,0,0" Stroke="Black" /&gt;
          &lt;/StackPanel&gt;
      &lt;/StackPanel&gt;
  </code></pre>
  
  <p>
  ColourSelection Code Behind:</p>
  
  <pre><code>public partial class ColourSelection : UserControl
  {
    public ColourSelection()
    {
      InitializeComponent();
    }
  
    public SolidColorBrush Colour
    {
      get { return (SolidColorBrush)GetValue(ColourProperty); }
      set { SetValue(ColourProperty, value); }
    }
  
    public static readonly DependencyProperty ColourProperty = DependencyProperty.Register
    (
      "Colour",
      typeof(SolidColorBrush),
      typeof(ColourSelection),
      new PropertyMetadata(null)
    );
  
    public int R
    {
      get { return (int)GetValue(RProperty); }
      set
      {
        if (value &lt;= 255 &amp;&amp; value &gt;= 0)
        {
          SetValue(RProperty, value);
          UpdateColour();
        }
      }
    }
  
    public static readonly DependencyProperty RProperty = DependencyProperty.Register
    (
      "R",
      typeof(int),
      typeof(ColourSelection),
      new PropertyMetadata()
    );
  
    public int G
    {
      get { return (int)GetValue(GProperty); }
      set
      {
        if (value &lt;= 255 &amp;&amp; value &gt;= 0)
        {
          SetValue(GProperty, value);
          UpdateColour();
        }
      }
    }
  
    public static readonly DependencyProperty GProperty = DependencyProperty.Register
    (
      "G",
      typeof(int),
      typeof(ColourSelection),
      new PropertyMetadata(null)
    );
  
    public int B
    {
      get { return (int)GetValue(BProperty); }
      set
      {
        if (value &lt;= 255 &amp;&amp; value &gt;= 0)
        {
          SetValue(BProperty, value);
          UpdateColour();
        }
      }
    }
    public static readonly DependencyProperty BProperty = DependencyProperty.Register
    (
      "B",
      typeof(int),
      typeof(ColourSelection),
      new PropertyMetadata(null)
    );
  
    void UpdateColour()
    {
      Colour = new SolidColorBrush(Color.FromRgb((byte)R, (byte)G, (byte)B));
    }
  }
  </code></pre>
  
  <p>Any help will be greatly appreciated.</p>