Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9017073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:10:17+00:00 2026-06-16T04:10:17+00:00

I have a custom control and I would like to tell every TextBlock inside

  • 0

I have a custom control and I would like to tell every TextBlock inside to use TextBlock.TextTrimming = CharacterEllipsis but I dont want to set that property on each individually. I mean even if later the user defines a ContentTemplate and places it inside my custom control and that ContentTemplate includes some Textblocks, they should automatically have set TextBlock.TextTrimming = CharacterEllipsis.

How do i do that? Any help please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:10:18+00:00Added an answer on June 16, 2026 at 4:10 am

    You could create an attached property with property value inheritance and apply that to your custom control, for example in its constructor. The attached property would copy its value to the target object, whenever the target object is a TextBlock.

    public class CustomControl : ContentControl
    {
        public CustomControl()
        {
            SetTextTrimming(this, TextTrimming.CharacterEllipsis);
        }
    
        public static readonly DependencyProperty TextTrimmingProperty =
            DependencyProperty.RegisterAttached(
                "TextTrimming", typeof(TextTrimming), typeof(CustomControl),
                new FrameworkPropertyMetadata(
                    default(TextTrimming),
                    FrameworkPropertyMetadataOptions.Inherits,
                    TextTrimmingPropertyChanged));
    
        public static TextTrimming GetTextTrimming(DependencyObject obj)
        {
            return (TextTrimming)obj.GetValue(TextTrimmingProperty);
        }
    
        public static void SetTextTrimming(DependencyObject obj, TextTrimming value)
        {
            obj.SetValue(TextTrimmingProperty, value);
        }
    
        private static void TextTrimmingPropertyChanged(
            DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            var textBlock = obj as TextBlock;
    
            if (textBlock != null)
            {
                textBlock.TextTrimming = (TextTrimming)e.NewValue;
            }
        }
    }
    

    Note that there is no need to define this TextTrimming attached property in a derived control class. You could also define it in a special helper class, which does not even need to be derived from DependencyObject.

    The property also work fine with any other control that uses TextBoxes in their visual tree, for example a standard ContentControl:

    <ContentControl local:CustomControl.TextTrimming="WordEllipsis"
                    Content="Some sample text to be trimmed"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid control that I use throughout the application. I would like
I have a custom .ascx control and would like to set one of it's
In a WPF app I have a custom control. I would like the ToolTip
I have a custom control written in C# that I would like to port
I have a custom control (C#, visual studio). I want to show a tooltip
We have developed a custom control in monotouch (inherited from UITextField, but that shouldn't
I have a custom Windows controls that superclass standard ones. I would like my
I have a winforms project that I want to develop a custom control for.
I am building a custom control and what i would like to do is
I would like to write a ItemsControl derived custom control. This is partially from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.