c# - Silverlight RichtextBox Xaml 属性,无法设置值(异常)

标签 c# silverlight

您好,我想设置我的 silverlight 富文本框的 Xaml 属性。

this.Dispatcher.BeginInvoke(() =>
{
  richTextBox1.Xaml = "<Paragraph>Blah</Paragraph>";
});

但是我得到以下异常..

System.ArgumentException: value
   at System.Windows.Controls.RichTextBox.set_Xaml(String value)

有人能解释一下吗?
也许我不在

最佳答案

您实际上想为字符串添加一个 XML 命名空间,以便解析 Paragraph 对象。喜欢:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

因为您真的只需要一个 xmlns 条目,所以用一个 Section block 将其包围。您的完整工作字符串将是这样的:

richTextBox1.Xaml = "<Section xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><Paragraph>Blah</Paragraph></Section>";

为了解决这个问题,我在 RichTextBox 中输入了文本(例如“Blah”),然后查看了 textbox1.Xaml 属性(始终先使用工作方法进行调查,看看结果如何) .

关于c# - Silverlight RichtextBox Xaml 属性,无法设置值(异常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3856278/

相关文章:

silverlight - 模拟器上的隔离存储总是空的?

C# 将 Json 字符串解析为数组(相当于 Javascript 中的 Json.parse)

c# - 在 mvc4 中捕获未处理的异常

c# - 如何使用公共(public)列在 C# 中对 2 个或多个数据表进行完全外部联接

c# - 在 Silverlight 中使用 DataForm 中的密码文本框

c# - 提交试用版WP7应用

c# - 使用 Silverlight 播放用户的歌曲

c# - 将字节数组转换为托管结构

c# - 业务库重用或公开服务

wpf - 嵌入在 ContentControl 中的交互触发器