【发布时间】:2014-05-07 01:37:54
【问题描述】:
在一个非常简单的 WPF 应用程序中,我在 button1_click() 方法中有以下代码:
textBlock1.Inlines.Add(new Run("TextBlock is designed to be lightweight."));
canvas.Children.Add(textBlock1);
Debug.Print("textBlock1.Text: {0}", textBlock1.Text);
Debug.Print 语句不会为 Text 属性打印任何内容,但实际文本(即“TextBlock is designed...”)在画布上的 TextBlock 控件中可见。为什么Text 属性没有描述Inlines 的精确副本?
PS:没有使用数据绑定等。该项目非常简单,在 MainWindow 内的 Canvas 上有一个 TextBlock 和一个 Button,以及最小的 XAML;一切都在代码隐藏中处理。
【问题讨论】:
-
我只能建议,当您手动添加 TextBlock.Inlines 时,更改不会反映在 TextBlock.Text 属性上。但是如果你尝试指定 TextBlock.Text 属性,TextBlock.Inlines 集合将被正确修改。
-
@stukselbax 谢谢。