none
Create "Inlines"-Property for custom TextBlock-Control?

    Question

  • Hello!

    I've created my own custom TextBlock-Control, which works so far and now I would like to add "Run"-Elements to the Inlines-Property in codebehind. But the Inlines-Property don't exist in my control at the moment and my question is, what I must do to have the same property and behaviour in my control?

    Here is my code:

    using System.Windows.Controls;
    using System.ComponentModel;
    using System.Windows;
    
    namespace My_Controls.Controls
    {
        [Description("Textblock BaseClass"), Category("Common Properties")]
        public class My_TextBlock : Control
        {
            public My_TextBlock()
            {
                this.DefaultStyleKey = typeof(My_TextBlock);
                this.FontFamily = new System.Windows.Media.FontFamily("Arial");
                this.FontSize = 11;
          
            }
    
    
            public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(My_TextBlock), new PropertyMetadata(" "));
    
            [Description("Text Property."), Category("Common Properties")]
            public string Text
            {
                get { return GetValue(TextProperty) as string; }
                set { SetValue(TextProperty, value); }
            }
    
            public string Content
            {
                get
                {
                    return this.Text;
                }
                set
                {
                    this.Text = value;
                }
            }
    
            public override void OnApplyTemplate()
            {
                base.OnApplyTemplate();
            }
        }
    }

    Thank you in advance for your answers!

    Best Regards

    Malone

    Thursday, March 15, 2012 11:32 AM

All replies

  • i Malone,
    As we all know that the TextBlock Inlines property is not a DependencyProperty. So we can't bind it in the code behind directly. You can create inlines property through an attached property and Data Binding converter.

    Best wishes,

    Monday, April 09, 2012 11:27 PM