title: How to inherit a textblock properties to a custom control in c#
body: <p>I have a custom wpf control. It is basically a textblock which has an ability to apply fill and stroke to the text.
  It is already inherited by a class.
  The problem is that it does not have some textblock properties like fontfamily.
  I want to inherit this control  with textblock so it can use its all properties.
  The custom control code is given below</p>
  
  <pre><code>namespace CustomXaml
  {
  public class OutlinedText : FrameworkElement, IAddChild
  {
  #region Private Fields
  
  private Geometry _textGeometry;
  
  #endregion
  
  #region Private Methods
  
  /// &lt;summary&gt;
  /// Invoked when a dependency property has changed. Generate a new FormattedText object to display.
  /// &lt;/summary&gt;
  /// &lt;param name="d"&gt;OutlineText object whose property was updated.&lt;/param&gt;
  /// &lt;param name="e"&gt;Event arguments for the dependency property.&lt;/param&gt;
  private static void OnOutlineTextInvalidated(DependencyObject d, DependencyPropertyChangedEventArgs e)
  {
      ((OutlinedText)d).CreateText();
  }
  
  #endregion
  
  
  #region FrameworkElement Overrides
  
  /// &lt;summary&gt;
  /// OnRender override draws the geometry of the text and optional highlight.
  /// &lt;/summary&gt;
  /// &lt;param name="drawingContext"&gt;Drawing context of the OutlineText control.&lt;/param&gt;
  protected override void OnRender(DrawingContext drawingContext)
  {
      CreateText();
      // Draw the outline based on the properties that are set.
      drawingContext.DrawGeometry(Fill, new Pen(Stroke, StrokeThickness), _textGeometry);
  
  }
  
  /// &lt;summary&gt;
  /// Create the outline geometry based on the formatted text.
  /// &lt;/summary&gt;
  public void CreateText()
  {
      FontStyle fontStyle = FontStyles.Normal;
      FontWeight fontWeight = FontWeights.Medium;
  
      if (Bold == true) fontWeight = FontWeights.Bold;
      if (Italic == true) fontStyle = FontStyles.Italic;
  
      // Create the formatted text based on the properties set.
      FormattedText formattedText = new FormattedText(
          Text,
          CultureInfo.GetCultureInfo("en-us"),                
          FlowDirection.LeftToRight,
          new Typeface(Font, fontStyle, fontWeight, FontStretches.Normal),                
          FontSize,
          Brushes.Black // This brush does not matter since we use the geometry of the text. 
          );
  
      // Build the geometry object that represents the text.
      _textGeometry = formattedText.BuildGeometry(new Point(0, 0));
  
  
  
  
      //set the size of the custome control based on the size of the text
      this.MinWidth = formattedText.Width;
      this.MinHeight = formattedText.Height;
  
  }
  
  #endregion
  
  #region DependencyProperties
  
  /// &lt;summary&gt;
  /// Specifies whether the font should display Bold font weight.
  /// &lt;/summary&gt;
  public bool Bold
  {
      get
      {
          return (bool)GetValue(BoldProperty);
      }
  
      set
      {
          SetValue(BoldProperty, value);
      }
  }
  
  /// &lt;summary&gt;
  /// Identifies the Bold dependency property.
  /// &lt;/summary&gt;
  public static readonly DependencyProperty BoldProperty = DependencyProperty.Register(
      "Bold",
      typeof(bool),
      typeof(OutlinedText),
      new FrameworkPropertyMetadata(
          false,
          FrameworkPropertyMetadataOptions.AffectsRender,
          new PropertyChangedCallback(OnOutlineTextInvalidated),
          null
          )
      );
  
  /// &lt;summary&gt;
  /// Specifies the brush to use for the fill of the formatted text.
  /// &lt;/summary&gt;
  public Brush Fill
  {
      get
      {
          return (Brush)GetValue(FillProperty);
      }
  
      set
      {
          SetValue(FillProperty, value);
      }
  }
  
  /// &lt;summary&gt;
  /// Identifies the Fill dependency property.
  /// &lt;/summary&gt;
  public static readonly DependencyProperty FillProperty = DependencyProperty.Register(
      "Fill",
      typeof(Brush),
      typeof(OutlinedText),
      new FrameworkPropertyMetadata(
          new SolidColorBrush(Colors.LightSteelBlue),
          FrameworkPropertyMetadataOptions.AffectsRender,
          new PropertyChangedCallback(OnOutlineTextInvalidated),
          null
          )
      );
  
  /// &lt;summary&gt;
  /// The font to use for the displayed formatted text.
  /// &lt;/summary&gt;
  public FontFamily Font
  {
      get
      {
          return (FontFamily)GetValue(FontProperty);
      }
  
      set
      {
          SetValue(FontProperty, value);
      }
  }
  
  /// &lt;summary&gt;
  /// Identifies the Font dependency property.
  /// &lt;/summary&gt;
  public static readonly DependencyProperty FontProperty = DependencyProperty.Register(
      "Font",
      typeof(FontFamily),
      typeof(OutlinedText),
      new FrameworkPropertyMetadata(
          new FontFamily("Arial"),
          FrameworkPropertyMetadataOptions.AffectsRender,
          new PropertyChangedCallback(OnOutlineTextInvalidated),
          null
          )
      );
  
  /// &lt;summary&gt;
  /// The current font size.
  /// &lt;/summary&gt;
  public double FontSize
  {
      get
      {
          return (double)GetValue(FontSizeProperty);
      }
  
      set
      {
          SetValue(FontSizeProperty, value);
      }
  }
  
  /// &lt;summary&gt;
  /// Identifies the FontSize dependency property.
  /// &lt;/summary&gt;
  public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register(
      "FontSize",
      typeof(double),
      typeof(OutlinedText),
      new FrameworkPropertyMetadata(
           (double)48.0,
           FrameworkPropertyMetadataOptions.AffectsRender,
           new PropertyChangedCallback(OnOutlineTextInvalidated),
           null
           )
      );
  
  
  /// &lt;summary&gt;
  /// Specifies whether the font should display Italic font style.
  /// &lt;/summary&gt;
  public bool Italic
  {
      get
      {
          return (bool)GetValue(ItalicProperty);
      }
  
      set
      {
          SetValue(ItalicProperty, value);
      }
  }
  
  /// &lt;summary&gt;
  /// Identifies the Italic dependency property.
  /// &lt;/summary&gt;
  public static readonly DependencyProperty ItalicProperty = DependencyProperty.Register(
      "Italic",
      typeof(bool),
      typeof(OutlinedText),
      new FrameworkPropertyMetadata(
           false,
           FrameworkPropertyMetadataOptions.AffectsRender,
           new PropertyChangedCallback(OnOutlineTextInvalidated),
           null
           )
      );
  
  /// &lt;summary&gt;
  /// Specifies the brush to use for the stroke and optional hightlight of the formatted text.
  /// &lt;/summary&gt;
  public Brush Stroke
  {
      get
      {
          return (Brush)GetValue(StrokeProperty);
      }
  
      set
      {
          SetValue(StrokeProperty, value);
      }
  }
  
  /// &lt;summary&gt;
  /// Identifies the Stroke dependency property.
  /// &lt;/summary&gt;
  public static readonly DependencyProperty StrokeProperty = DependencyProperty.Register(
      "Stroke",
      typeof(Brush),
      typeof(OutlinedText),
      new FrameworkPropertyMetadata(
           new SolidColorBrush(Colors.Teal),
           FrameworkPropertyMetadataOptions.AffectsRender,
           new PropertyChangedCallback(OnOutlineTextInvalidated),
           null
           )
      );
  
  /// &lt;summary&gt;
  ///     The stroke thickness of the font.
  /// &lt;/summary&gt;
  public ushort StrokeThickness
  {
      get
      {
          return (ushort)GetValue(StrokeThicknessProperty);
      }
  
      set
      {
          SetValue(StrokeThicknessProperty, value);
      }
  }
  
  /// &lt;summary&gt;
  /// Identifies the StrokeThickness dependency property.
  /// &lt;/summary&gt;
  public static readonly DependencyProperty StrokeThicknessProperty = DependencyProperty.Register(
      "StrokeThickness",
      typeof(ushort),
      typeof(OutlinedText),
      new FrameworkPropertyMetadata(
           (ushort)0,
           FrameworkPropertyMetadataOptions.AffectsRender,
           new PropertyChangedCallback(OnOutlineTextInvalidated),
           null
           )
      );
  
  /// &lt;summary&gt;
  /// Specifies the text string to display.
  /// &lt;/summary&gt;
  public string Text
  {
      get
      {
          return (string)GetValue(TextProperty);
      }
  
      set
      {
          SetValue(TextProperty, value);
      }
  }
  
  /// &lt;summary&gt;
  /// Identifies the Text dependency property.
  /// &lt;/summary&gt;
  public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
      "Text",
      typeof(string),
      typeof(OutlinedText),
      new FrameworkPropertyMetadata(
           "",
           FrameworkPropertyMetadataOptions.AffectsRender,
           new PropertyChangedCallback(OnOutlineTextInvalidated),
           null
           )
      );
  
  public void AddChild(Object value)
  {
  
  }
  
  public void AddText(string value)
  {
      Text = value;
  }
  
  #endregion
  }
  }
  </code></pre>