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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:45:06+00:00 2026-05-13T08:45:06+00:00

I want a multiline textbox which shows apostrophes before and after each line. So

  • 0

I want a multiline textbox which shows apostrophes before and after each line.
So that the textbox looks like:

" Hello this  "
" is a funny  "
" string test "

Or for example:

// This is
// a muliline
// comment.

Edit: These special characters must be readonly and if the user copies text from the textbox these characters should not be included.

  • 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-05-13T08:45:07+00:00Added an answer on May 13, 2026 at 8:45 am

    This is very easy using two textboxes laid directly over one another. The rear one is a normal textbox with extra padding and transparent text. The front one has your extra characters but has its borders hidden and is IsHitTestVisible=False and Focusable=False so it doesn’t interact with the user. The user interacts exclusively with the rear textbox but the front textbox is the one that displays the text. A binding with a value converter keeps the front textbox displaying exactly what the rear textbox displays, plus the extra characters.

    This is how it would look:

    <ControlTemplate x:Key="TextBoxWithExtraCharacters" TargetType="{x:Type TextBox}">
      <ControlTemplate.Resources>
        <!-- Remove the border from the inner textboxes -->
        <ControlTemplate TargetType="{x:Type TextBox}">
          <Decorator x:Name="PART_Content" />
        </ControlTemplate>
      </ControlTemplate.Resources>
    
      <!-- Now add our own border -->
      <Border
        BorderThickness="{TemplateBinding BorderThickness}"
        BorderBrush="{TemplateBinding BorderBrush}"
        Background="{TemplateBinding Background}"
        SnapsToDevicePixels="true">
    
        <!-- Scrolling must happen at this level so both text boxes scroll simultaneously -->
        <ScrollViewer>
          <Grid>
            <!-- Rear textbox provides editing and user interaction but the text is transparent -->
            <TextBox
              Margin="10,0,10,0"
              Foreground="Transparent"
              Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}"
              Background="{x:Null}"
              IsReadOnly="{TemplateBinding IsReadOnly}"
              IsUndoEnabled="{TemplateBinding IsUndoEnabled}"
              AcceptsReturn="{TemplateBinding AcceptsReturn}"
              AcceptsTab="{TemplateBinding AcceptsTab}"
            />
            <!-- Front textbox displays modified text but does not interact with user -->
            <TextBox
              IsHitTestVisible="false"
              Focusable="false"
              Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, 
                                   Converter={x:Static ExtraCharacterConverter.Instance}"
              Background="{x:Null}"
              IsReadOnly="{TemplateBinding IsReadOnly}"
              IsUndoEnabled="{TemplateBinding IsUndoEnabled}"
              AcceptsReturn="{TemplateBinding AcceptsReturn}"
              AcceptsTab="{TemplateBinding AcceptsTab}"
            />
          </Grid>
        </ScrollViewer>
      </Border>
    </ControlTemplate>
    

    ExtraCharacterConverter is a simple IValueConverter class that implements the Convert method by taking the given string, appending quotes or // or whatever to it, and returning the result.

    Note that I hard-coded a left and right margin of 10 units on the rear textbox, which assumes a particular width for the quote characters. This should be exactly the width of the added characters to make the text line up correctly. You want to get this right, or your caret and text selection positioning will be wrong. Also note that the correct value will change as you vary your font size and your choice of extra characters.

    An easy alternative to hard-coding the margin would be to set it to a multi-binding on FontSize, FontFamily, FontWeight, etc, then use a IMultiValueConverter to compute the proper margin given this these values.

    Note: This solution is slighly unsatisfactory when it comes to the color scheme for text selection. This can be fixed, but it requires a more complex solution: The rear text box is the same but its text is not invisible. The front text box is replaced with a RichTextBox (or TextBlock) whose content is computed dynamically to be the text with extra characters, but the regular text transparent. Because it is a RichTextBox the extra characters can be visible while the others are transparent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In silverlight, I got a textbox which I want to be multiline and have
I want to implement a fancy scroll bar for a multiline textbox like the
I've got a multiline textBox that I would like to have a label on
I have a Multiline Textbox . I donot want to let user type HTML
I am using the winforms textbox with multiline option ON. I want to limit
I want to create a simple multiline Alert popup Alert.show(Blah\\nBlah) shows Blah\nBlah when what
I want to display a list of complex, but fixed-size multiline elements, assuming that
I have a DevExpress GridControl and i want each cell to be multiline. I
I've got a multi line text file that I want to use to create
This is for a multiline textbox on an asp.net site. I can use either

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.