WPF TextWrapping on white spaces

谁都会走 提交于 2019-12-13 04:49:26

问题


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?


回答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.



来源:https://stackoverflow.com/questions/13161966/wpf-textwrapping-on-white-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!