I have TextBox I need to format the text if it is put in ctrl + v
I tried:
String str = Clipboard.GetText();
(sender as TextBox).Text += str.Replace("\r\n\r\n", "\r\n");
but this code throws an exception
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Format the text at the TextChanged event handler.
Update after comment:
You don’t need to do anything, just handle the textchange event:
XAML:
Code:
If the TextBox is only meant for text pasting, cosider setting its
IsReadOnlyproperty to true.Update after last comment:
Add the following to your code class: