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

  • Home
  • SEARCH
  • 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 3952500
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:51:29+00:00 2026-05-20T01:51:29+00:00

guys I want to input multi-line text into a DataGridTextColumn, I can use enter

  • 0

guys
I want to input multi-line text into a DataGridTextColumn, I can use “enter” to input a multi-line character. But i want use “shift+enter” like visual studio resource manager, here is my code with “enter” key.

<DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="*">
  <DataGridTextColumn.ElementStyle>
      <Style TargetType="TextBlock">
         <Setter Property="TextWrapping" Value="Wrap" />
      </Style>
  </DataGridTextColumn.ElementStyle>
  <DataGridTextColumn.EditingElementStyle>
      <Style TargetType="TextBox">
        <Setter Property="TextWrapping" Value="Wrap" />
        <Setter Property="AcceptsReturn" Value="true" />
      </Style>
  </DataGridTextColumn.EditingElementStyle>

  • 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-20T01:51:30+00:00Added an answer on May 20, 2026 at 1:51 am

    One way you can do this is by handling the KeyDown event on the TextBox using an EventSetter in your Style. I took your example, removed the AcceptsReturn setter in the style, and added a KeyDown handler to the EditingElementStyle that adds a newline to where the caret was and moves the CaretIndex to the right.

    Here’s the XAML:

    <DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="*">
        <DataGridTextColumn.ElementStyle>
            <Style TargetType="TextBlock">
                <Setter Property="TextWrapping" Value="Wrap" />
            </Style>
        </DataGridTextColumn.ElementStyle>
        <DataGridTextColumn.EditingElementStyle>
            <Style TargetType="TextBox">
                <Setter Property="TextWrapping" Value="Wrap" />
                <EventSetter Event="KeyDown" Handler="OnTextBoxKeyDown"/>
            </Style>
        </DataGridTextColumn.EditingElementStyle>
    </DataGridTextColumn>
    

    I wrote the example in the Window class from a new Application project template, so here’s the C# for the whole Window with the event handling code. Note that I set Handled to true to stop the event from bubbling up anywhere as I don’t want the Return key to be handled as a commit to the editing row in this case. I think this is actually one of the downsides of the approach. Stopping the bubbling/tunneling of an event is something that, if you have complex interactions with user input in your application, can easily grow into a logic bomb. But it isn’t so bad if you just have one special case like this. So as with everything, use cautiously as the part of your UI using this grows.

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new List<Thing>
            {
                new Thing { Value = "Some text" },
                new Thing { Value = "More text" + Environment.NewLine + " second line" },
                new Thing { Value = "Another value" }
            };
        }
    
        private void OnTextBoxKeyDown(object sender, KeyEventArgs e)
        {
            if (Key.Return == e.Key && 
                0 < (ModifierKeys.Shift & e.KeyboardDevice.Modifiers))
            {
                var tb = (TextBox)sender;
                var caret = tb.CaretIndex;
                tb.Text = tb.Text.Insert(caret, Environment.NewLine);
                tb.CaretIndex = caret + 1;
                e.Handled = true;
            }
        }
    }
    
    public class Thing
    {
        public string Value { get; set; }
    }
    

    One other thing to consider is that you may want the behavior to be different if the insert key has been pressed and you are in override input mode. Maybe in this case, the next character should be replaced by the new line. But the resource editor in Visual Studio 2010 doesn’t seem to react to the insert key (it also doesn’t show the text as multi-line). But I think given this example, you could extend it to work well with the insert key. Hope this helps – good luck!

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

Sidebar

Related Questions

Hey guys I want a form to be submitted but it just won't work
Hey guys i wrote a quick test. I want delete to call deleteMe which
Guys, can someone give me a brief run through of how to change the
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development
Hi Guys can you please help me with this error? What is it? Server
Hey guys I'm currenlty working on something and I want if I click a
Guys, I need to develop a tool which would meet following requirements: Input: XHTML
I want to disable the default contextMenu when a user right-clicks on an input
hai guys, As i am a newbie i want to check a file path
Hey guys, I'm creating a DLL in C++ and I want it to be

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.