title: Why UserControl without XAML controls do not inherit properties?
body: <p>I had a working user control done in WPF in XAML. Now I have removed the XAML and created the usercontrol with code because I need to inherit from this control. Previosuly I had code like this one on the code using the control:</p>
  
  <pre><code>&lt;mc:MyControl Foreground="White"&gt;
  </code></pre>
  
  <p>And all the controls inside the MyControl control used this Foreground setting. Now that I've created the control just using C# this is not happening anymore.</p>
  
  <p>Someone know why and how to fix this?</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: </p>
  
  <p>This is the XAML:</p>
  
  <pre><code>&lt;UserControl x:Class="Utils.Wpf.Chart.Chart"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           SizeChanged="UserControl_SizeChanged"&gt;
  &lt;Grid&gt;
      &lt;Border Margin="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"&gt;
          &lt;Grid&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="Auto"/&gt;
                  &lt;ColumnDefinition Width="*"/&gt;
                  &lt;ColumnDefinition Width="*"/&gt;
              &lt;/Grid.ColumnDefinitions&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height="*"/&gt;
                  &lt;RowDefinition Height="*"/&gt;
                  &lt;RowDefinition Height="Auto"/&gt;
              &lt;/Grid.RowDefinitions&gt;
  
              &lt;Canvas Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="0" Grid.RowSpan="2"  x:Name="DrawArea" Canvas.Background="Transparent" MouseEnter="DrawArea_MouseEnter" MouseLeave="DrawArea_MouseLeave" MouseMove="DrawArea_MouseMove" Cursor="None"&gt;
                  &lt;Line x:Name="Border1" X1="0" X2="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" Y1="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" Y2="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" StrokeThickness="1" Stroke="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/&gt;
                  &lt;Line x:Name="Border2" Y1="0" Y2="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}}" X1="0" X2="0" StrokeThickness="1" Stroke="{Binding BorderBrush, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"/&gt;
                  &lt;TextBlock x:Name="CrossValue" Text="[-,-]" Foreground="#EBDE11" Visibility="Hidden"/&gt;
              &lt;/Canvas&gt;
  
              &lt;TextBlock Grid.Column="0" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Right" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MaxYCaption, TargetNullValue=MaxY}" Margin="3,0,6,0"/&gt;
              &lt;TextBlock Grid.Column="0" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MinYCaption, TargetNullValue=MinY}" Margin="3,0,6,0"/&gt;
  
              &lt;TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MinX, TargetNullValue=MinX}" Margin="3,3,0,0"/&gt;
              &lt;TextBlock Grid.Column="2" Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Top" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=MaxX, TargetNullValue=MaxX}" Margin="0,3,3,0"/&gt;
          &lt;/Grid&gt;
      &lt;/Border&gt;
  &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>This is the C#:</p>
  
  <pre><code>        _outerGrid = new Grid();
          _border = new Border();
          _innerGrid = new Grid();
          _canvas = new Canvas();
          _line1 = new Line();
          _line2 = new Line();
          _cursorText = new TextBlock();
          _maxXText = new TextBlock();
          _maxYText = new TextBlock();
          _minXText = new TextBlock();
          _minYText = new TextBlock();
  
          this.Content = _outerGrid;
  
          _border.Margin = new Thickness(5);
          _border.HorizontalAlignment = HorizontalAlignment.Stretch;
          _border.VerticalAlignment = VerticalAlignment.Stretch;
  
          _outerGrid.Children.Add(_border);
  
          _column1 = new ColumnDefinition();
          _column1.Width = new GridLength(0, GridUnitType.Auto);
          _column2 = new ColumnDefinition();
          _column2.Width = new GridLength(1, GridUnitType.Star);
          _column3 = new ColumnDefinition();
          _column3.Width = new GridLength(1, GridUnitType.Star);
  
          _row1 = new RowDefinition();
          _row1.Height = new GridLength(1, GridUnitType.Star);
          _row2 = new RowDefinition();
          _row2.Height = new GridLength(1, GridUnitType.Star);
          _row3 = new RowDefinition();
          _row3.Height = new GridLength(0, GridUnitType.Auto);
  
          _innerGrid.ColumnDefinitions.Add(_column1);
          _innerGrid.ColumnDefinitions.Add(_column2);
          _innerGrid.ColumnDefinitions.Add(_column3);
  
          _innerGrid.RowDefinitions.Add(_row1);
          _innerGrid.RowDefinitions.Add(_row2);
          _innerGrid.RowDefinitions.Add(_row3);
  
          _border.Child = _innerGrid;
  
          _canvas.Background = Brushes.Transparent;
          _canvas.Cursor = Cursors.None;
          _canvas.MouseEnter += new MouseEventHandler(_canvas_MouseEnter);
          _canvas.MouseMove += new MouseEventHandler(_canvas_MouseMove);
          _canvas.MouseLeave += new MouseEventHandler(_canvas_MouseLeave);
  
          Grid.SetColumn(_canvas,1);
          Grid.SetColumnSpan(_canvas,2);
          Grid.SetRowSpan(_canvas,2);
  
          _innerGrid.Children.Add(_canvas);
  
          _line1.X1 = 0;
          _line1.StrokeThickness = 1;
  
          Binding x2Binding = new Binding("ActualWidth");
          x2Binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) {AncestorType = _canvas.GetType()};
          _line1.SetBinding(Line.X2Property, x2Binding);
  
          Binding yBinding = new Binding("ActualHeight");
          yBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = _canvas.GetType() };
          _line1.SetBinding(Line.Y1Property, yBinding);
          _line1.SetBinding(Line.Y2Property, yBinding);
  
          _line2.Y1 = 0;
          _line2.X1 = 0;
          _line2.X2 = 0;
          _line2.StrokeThickness = 1;
  
          Binding y2Binding = new Binding("ActualHeight");
          y2Binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = _canvas.GetType() };
          _line2.SetBinding(Line.Y2Property, x2Binding);
  
          Binding strokeBinding = new Binding("BorderBrush");
          strokeBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
          _line2.SetBinding(Shape.StrokeProperty, strokeBinding);
  
          _cursorText.Text = "[-,-]";
          _cursorText.Foreground = new SolidColorBrush(Color.FromRgb(0xeb, 0xde, 11));
          _cursorText.Visibility = Visibility.Hidden;
  
          _canvas.Children.Add(_line1);
          _canvas.Children.Add(_line2);
          _canvas.Children.Add(_cursorText);
  
          _maxYText.VerticalAlignment = VerticalAlignment.Top;
          _maxYText.HorizontalAlignment = HorizontalAlignment.Right;
          _maxYText.Margin = new Thickness(3, 0, 6, 0);
  
          Binding maxYBinding = new Binding("MaxYCaption");
          maxYBinding.TargetNullValue = "MaxY";
          maxYBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
          _maxYText.SetBinding(TextBlock.TextProperty, maxYBinding);
  
          _minYText.VerticalAlignment = VerticalAlignment.Bottom;
          _minYText.HorizontalAlignment = HorizontalAlignment.Right;
          _minYText.Margin = new Thickness(3, 0, 6, 0);
  
          Binding minYBinding = new Binding("MinYCaption");
          minYBinding.TargetNullValue = "MinY";
          minYBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
          _minYText.SetBinding(TextBlock.TextProperty, minYBinding);
  
          _maxXText.VerticalAlignment = VerticalAlignment.Top;
          _maxXText.HorizontalAlignment = HorizontalAlignment.Right;
          _maxXText.Margin = new Thickness(0, 3, 3, 0);
  
          Binding maxXBinding = new Binding("MaxX");
          maxXBinding.TargetNullValue = "MaxX";
          maxXBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
          _maxXText.SetBinding(TextBlock.TextProperty, maxXBinding);
  
          _minXText.VerticalAlignment = VerticalAlignment.Top;
          _minXText.HorizontalAlignment = HorizontalAlignment.Left;
          _minXText.Margin = new Thickness(3, 3, 0, 0);
  
          Binding minXBinding = new Binding("MinX");
          minXBinding.TargetNullValue = "MinX";
          minXBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(UserControl) };
          _minXText.SetBinding(TextBlock.TextProperty, minXBinding);
  
          _innerGrid.Children.Add(_maxYText);
          _innerGrid.Children.Add(_maxXText);
          _innerGrid.Children.Add(_minYText);
          _innerGrid.Children.Add(_minXText);
  
          Grid.SetColumn(_maxXText, 2);
          Grid.SetColumn(_minXText, 1);
          Grid.SetRow(_minYText, 1);
          Grid.SetRow(_minXText, 2);
          Grid.SetRow(_maxXText, 2);
  
          this.SizeChanged += new System.Windows.SizeChangedEventHandler(Chart2_SizeChanged);
  </code></pre>