简体   繁体   中英

TextBlock issue when long text and TextTrimming

I have a TextBlock with TextTrimming="CharacterEllipsis" , TextWrapping="NoWrap" and very long text about 140 000 symbols. I put this text into the TextBlock, and then the TextBlock shows this text as multiline control whith trimming in an each row.

XAML

    <Window x:Class="WpfApplication3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <TextBlock x:Name="textBlock" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" Width="500"/>
        </Grid>
    </Window>

C#

    public partial class MainWindow : Window {
            public MainWindow() {
                InitializeComponent();
                string str = "q ";
                for(int i = 0; i < 20000; i++) {
                    str += "qwetre ";
                }
                textBlock.Text = str;
            }
        }


Any ideas? Is it bug of MS, or I can change this behaviour?

The Textblock TextWrapping property is by default set to NoWrap.

Therefore, unless you

  1. explicitly set it to Wrap/WrapWithOverflow or
  2. add <LineBreak/> tags with the text

the text will always be displayed over one line only.

@Mirimon I ran this project exactly as you have shown and I only see one row!

I have found answer on my question. The TextBlock has this behaviour with 4.5 framework (I had install VS2012), I tried in on computer without VS2012, work correctly, only one row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM