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 7934183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:34:07+00:00 2026-06-03T21:34:07+00:00

I have a TextBox in WPF like so: <TextBox Height=48 /> Nothing special, looks

  • 0

I have a TextBox in WPF like so:

<TextBox Height="48" />

Nothing special, looks like this:

enter image description here

Now what I need to accomplish is to have clear and nice long line markers:

enter image description here

So basically I want to draw a line marker at position 50. I will use a fixed-width font to make this easier for myself so I can calculate the position easily.

Now the thing is, I don’t want to restrict typing over it, but I want it to give a visual glue when you reached the 50 character limit.

To make matters harder, I need this limit to be higher for the following lines/rows (72 characters) like so:

enter image description here

The line markers sharing the same position (rows 2 – n) could be a single line rather than multiple.

I’m also open to other suggestions, but as long as it offers a clean way to tell the user he is about to exceed the limit, I’m cool with it.

Note: I don’t want any text saying that “you have x characters left” or something. Space is limited and I want it to be visual.

Update: I would really appreciate if it was possible to add a tooltip so that when hovering a marker it stated its purpose to the user.

  • 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-03T21:34:10+00:00Added an answer on June 3, 2026 at 9:34 pm

    Since you want to visually decorate the Textbox, the first thing that pops to my mind is the aptly named Adnorner.

    I have written a quick demo showing how to adorn a Textbox. The line drawing part is easy, the tricky part will be to figure out where the lines should be drawn. I have hard coded the line positions in my example. I supposed you would have to do some sort of text measuring to find out how tall your texts are(for the line height) and how long is 50 chars worth(to offset your lines by).

    enter image description here

    Here is the xaml:

    <Window x:Class="WpfApplication4.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid  HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" >
            <AdornerDecorator>
                <TextBox TextWrapping="Wrap"  AcceptsReturn="True" x:Name="myTextBox" Width="200px" Height="200px">hello</TextBox>
            </AdornerDecorator>
        </Grid>
    </Window>
    

    And the code behind

    using System.Windows;
    using System.Windows.Documents;
    using System.Windows.Media;
    
    namespace WpfApplication4
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(myTextBox);
                myAdornerLayer.Add(new LineAdorner(myTextBox));
            }
    
            // Adorners must subclass the abstract base class Adorner.
    
            #region Nested type: LineAdorner
    
            public class LineAdorner : Adorner
            {
                // Be sure to call the base class constructor.
                public LineAdorner(UIElement adornedElement)
                    : base(adornedElement)
                {
                }
    
                // A common way to implement an adorner's rendering behavior is to override the OnRender
                // method, which is called by the layout system as part of a rendering pass.
                protected override void OnRender(DrawingContext drawingContext)
                {
                    var adornedElementRect = new Rect(AdornedElement.DesiredSize);
    
                    var renderPen = new Pen(new SolidColorBrush(Colors.Red), 1.5);
    
                    // Draw lines.
                    drawingContext.DrawLine(renderPen,
                                            new Point(adornedElementRect.TopLeft.X + 75, adornedElementRect.TopLeft.Y),
                                            new Point(adornedElementRect.TopLeft.X + 75, adornedElementRect.TopLeft.Y + 20));
                    drawingContext.DrawLine(renderPen,
                                            new Point(adornedElementRect.TopLeft.X + 120, adornedElementRect.TopLeft.Y + 20),
                                            new Point(adornedElementRect.TopLeft.X + 120, adornedElementRect.TopLeft.Y + 40));
                    drawingContext.DrawLine(renderPen,
                                            new Point(adornedElementRect.TopLeft.X + 120, adornedElementRect.TopLeft.Y + 40),
                                            new Point(adornedElementRect.TopLeft.X + 120, adornedElementRect.TopLeft.Y + 60));
                }
            }
    
            #endregion
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF TextBox, defined like this: <TextBox Text={Binding Path=/Comments} Margin=351,193.91,10,36 x:Name=txtComments IsReadOnly=True
I have a WPF StackPanel that looks like this: (some attributes removed that don't
This other SO question asks about an autocomplete textbox in WPF. Several people have
Say I have a 3-level data-bound WPF TreeView like this one: a aa aaa
I have a template like this, <Style x:Key=WaterMarkTextBoxStyle BasedOn={StaticResource {x:Type TextBox}} TargetType={x:Type TextBox}> <Setter
I have application with WPF Ribbon and Grid. And I need to show this
I have a WPF textBox that is declared as ReadOnly <TextBox IsReadOnly=True IsTabStop=False Width=200
I have a WPF TextBox in which I want to allow autocompleting user names
I have a TextBox in a WPF window bound to a dependency property of
I have a simple text box in a WPF application. I need to know

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.