Click here to Skip to main content
15,566,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a simple window and textbox when I try to paste this code to the textbox


name:abcc
age:20
sex:male


It stops after
name:abcc

I need to click enter after this , to add these details in another window.

What I have tried:

AcceptsReturn="True"

if I use AcceptsReturn="True" then enter click does not work. how to solve this problem?
Posted
Updated 7-Dec-20 0:09am
Comments
Richard MacCutchan 7-Dec-20 4:49am    
Without seeing your code it is impossible to guess what is needed. Please use the Improve question link above and add some proper details.

1 solution

There is a workaround.
XML
<TextBox Name="MyTextBox"
	 Width="250"
	 Height="60"
	 AcceptsReturn="True"
	 PreviewKeyDown="MyTextBox_OnPreviewKeyDown">
</TextBox>

You can use the PreviewKeyDown event.
In your Event Handler do not forget to get rid of the trailing line feeds by using Trim().
C#
private void MyTextBox_OnPreviewKeyDown(object sender, KeyEventArgs e)
{
	if (e.Key == Key.Enter)
	{
		MessageBox.Show(MyTextBox.Text.Trim());
	}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900