文本块的 TextTrimming 属性不起作用

发布于 2024-12-18 11:36:56 字数 852 浏览 2 评论 0原文

我可以为 TextBlock 找到一个名为 TextTrimming 的属性,但我无法让它工作。 我在主页中有一个文本块,旨在提供预览。当我单击按钮时,如果其中保存了任何注释,我需要显示几个字符。

即使我设置了 TextTrimming 属性,也会显示整个文本。我尝试减小文本块的宽度,但它仍然在整个屏幕上显示文本 strechin

这是 xaml 代码

<TextBlock 
     Height="27" 
     HorizontalAlignment="Left" 
     x:Name="notesPreview" 
     Text="" 
     VerticalAlignment="Top" 
     Width="236" 
     Foreground="Gray" 
     Canvas.Left="20" 
     Canvas.Top="526" 
     TextTrimming="WordEllipsis" 
     MinWidth="236" />

我将文本分配给后面代码中的文本块,如下所示

if (m_bufferArrayNotes[i, j] != "")
{
    notes = m_bufferArrayNotes[i, j].Substring(0);
}
else
{
    notes = "";
}

notesPreview.TextTrimming = TextTrimming.WordEllipsis;
notesPreview.Text = notes;

文本块的大小展开并显示整个文本,并且可以看到同时平移到下一个枢轴项目:(。

有什么方法可以保持实际宽度静态吗?

I can find a property called TextTrimming for TextBlock, but I can't get it working.
I have a text block in the MainPage, which is intended to give a preview.. When i click a button if there is any notes saved in it, I need to display few characters.

Even when I have set the TextTrimming propery, the whole text is being shown. I tried reducing the width of the textblock but it still displays the text strechin the whole screen

This is the xaml code

<TextBlock 
     Height="27" 
     HorizontalAlignment="Left" 
     x:Name="notesPreview" 
     Text="" 
     VerticalAlignment="Top" 
     Width="236" 
     Foreground="Gray" 
     Canvas.Left="20" 
     Canvas.Top="526" 
     TextTrimming="WordEllipsis" 
     MinWidth="236" />

I assign the text to the textblock in the code behind like this

if (m_bufferArrayNotes[i, j] != "")
{
    notes = m_bufferArrayNotes[i, j].Substring(0);
}
else
{
    notes = "";
}

notesPreview.TextTrimming = TextTrimming.WordEllipsis;
notesPreview.Text = notes;

The size of the textblock expands and displays whole text and can be seen while pannin to the next pivot item :(.

Is there any way to keep the actual width static?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城追梦 2024-12-25 11:36:56

请参阅AppHub 上的此讨论论坛

他们建议使用此自定义实现来获得对 TextTrimming 的支持。

See this discussion on the AppHub forums.

They suggest using this custom implementation to get support for TextTrimming.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文