TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
13
5.3k
WPF richtextbox no line break in first line?
Jan 31 2018 12:17 PM
I experienced a weird bug and am unable to solve it.
To reproduce:
1. Create new wpf project
2. Add richtextbox, name it e.g. "rtb"
3. Append a text with line break at the end 3 times. For example
rtb.AppendText(
"lol\n"
);
rtb.AppendText(
"lol\n"
);
rtb.AppendText(
"lol\n"
);
4. Now start the application. Notice how everything works fine and there are three lines saying "lol".
5. Now clear the richtextbox before appending the lines:
rtb.Document.Blocks.Clear();
rtb.AppendText(
"lol\n"
);
rtb.AppendText(
"lol\n"
);
rtb.AppendText(
"lol\n"
);
6. Start the application again. Notice that the output is no longer
lol
lol
lol
but this time
lollol
lol
so essentially the "\n" for the first "lol" was added after the next "lol", lol?
Do you know what's going on because I don't. I'd expect it to output
lol
lol
lol
and I don't see why clearing the text content makes the richtextbox behave like this. I guess it's a bug but I don't understand why it's happening or how can I solve this.
It can't be because of "rtb.Document.Blocks.Clear()" as I've tried other methods for clearing the richtextbox as well, like
rtb.SelectAll();
rtb.Selection.Text =
""
;
and other approaches. However, none of them afterwards printed the text correctly. Now in this simple scenario, doing
rtb.Document.Blocks.Clear();
rtb.AppendText(
"lol\nlol\nlol\n"
);
(writing all 'lol's at once) actually does fix the issue. However I obviously don't just print out lol, but I have to call "AppendText" multiple times, resulting in incorrect output. Any ideas? Or where should I submit a bug report? Thanks.
Reply
Answers (
4
)
Top Web Designing Trends In 2018
How to get started on database