WPF TextWrapping on white spaces
Asked Answered
W

1

1

I am using a TextBlock in WPF, on which I want to use TextWrapping, What I have done in XAML is as follows.

<TextBlock TextWrapping="Wrap" Grid.Column="0" Grid.ColumnSpan="4" Grid.Row="0" Margin="5,5,5,5">
                                <TextBlock.Text>
                                    This is just a test. This is just a test.
                                </TextBlock.Text>
                            </TextBlock>

When I run this code it shows output like this

This is just a test. Th
is is just a test.

But I only want wrapping on white spaces like

This is just a test.
This is just a test.

I am unable to find why WPF is showing this behavior, I have tried WrapWithOverflow and IsHyphenationEnabled=true with no success. Please help me out?

Wakayama answered 31/10, 2012 at 15:57 Comment(3)
This shouldn't happen. my only guess is that one of its parents is setting a specific property and WPF is projecting it to the TextBlock's properties. try your code on a grid which is put directly in a window and see if the problem still occurs.Sleet
@Bizz, what could be that property? any idea?Wakayama
I don't know. but if you check it in its simplest situation, at least you know if it's because of your code of it's related to OS or a .Net build.Sleet
G
1

Bizz is right, this shouldn't be the behavior of Text Wrapping, Just a wild guess, are you copy/pasting text from some where to Visual studio? there might be an issue with white spaces in that case, and WPF will wrap your text in wrong way.

Glossy answered 28/11, 2012 at 6:0 Comment(1)
Thanks @madni for your suggestion, I was pasting the text from google translate, and surprisingly it was doing some bad thing with space character, I just replaced the space with actual space and it works fine. :)Wakayama

© 2022 - 2024 — McMap. All rights reserved.