简体   繁体   English

长文本和TextTrimming时出现TextBlock问题

[英]TextBlock issue when long text and TextTrimming

I have a TextBlock with TextTrimming="CharacterEllipsis" , TextWrapping="NoWrap" and very long text about 140 000 symbols. 我有一个TextBlock,它带有TextTrimming="CharacterEllipsis"TextWrapping="NoWrap"和非常长的文本,大约有140000个符号。 I put this text into the TextBlock, and then the TextBlock shows this text as multiline control whith trimming in an each row. 我将此文本放入TextBlock中,然后TextBlock将此文本显示为多行控件,并在每一行中进行修整。

XAML 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# 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? 是MS的错误,还是我可以更改此行为?

The Textblock TextWrapping property is by default set to NoWrap. 默认情况下,Textblock TextWrapping属性设置为NoWrap。

Therefore, unless you 因此,除非您

  1. explicitly set it to Wrap/WrapWithOverflow or 明确将其设置为Wrap / WrapWithOverflow或
  2. add <LineBreak/> tags with the text 在文本中添加<LineBreak/>标记

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! @Mirimon我完全按照您显示的方式运行了这个项目,我只看到一行!

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. TextBlock在4.5框架(我已安装VS2012)中具有此行为,我在没有VS2012的计算机上尝试使用,正常工作,只有一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过DynamicResource绑定文本时,在TextBlock上进行TextTrimming - TextTrimming on TextBlock while Text bound by DynamicResource 当 WPF 中的文本太长时,带有 slider 的 TextBlock - TextBlock with a slider when text is too long in WPF 当字符串太长时,以“…”打断文本块中的文本 - Interrupt text from a textblock with “…” when string is too long 使用GridSplitter放置在TreeViewItem中的TextBlock的TextTrimming属性 - TextTrimming property of TextBlock placed in TreeViewItem using GridSplitter WPF TextBlock TextTrimming在带有GridSplitter的网格内不起作用 - WPF TextBlock TextTrimming Not Working Inside a Grid With GridSplitter 如果文本太长,XAML TextBlock 绑定在末尾带有“...” - XAML TextBlock Binding with "..." at the end if text is too long 我正在使用WPF TextBlock,但是当文本太长时,文本会被切断。 是否有AutoScroll功能? - I'm using a WPF TextBlock but then text gets cut off when it's too long. Is there an AutoScroll feature? 如何获取TextBlock的TextTrimming的位置 - How can I get the location of a TextBlock's TextTrimming 如何防止带有 TextTrimming CharacterEllipsis 的 TextBlock 扩展具有自动宽度的列 - How to prevent a TextBlock with TextTrimming CharacterEllipsis to extend Column with Width Auto 运行时不显示整个文本时出现TextBlock - TextBlock when run not displaying entire text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM