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

Jul*_*Wit 1 c# silverlight

嗨,我想设置我的silverlight richtext框的Xaml属性.

this.Dispatcher.BeginInvoke(() =>
{
  richTextBox1.Xaml = "<Paragraph>Blah</Paragraph>";
});
Run Code Online (Sandbox Code Playgroud)

但是我得到以下异常..

System.ArgumentException: value
   at System.Windows.Controls.RichTextBox.set_Xaml(String value)
Run Code Online (Sandbox Code Playgroud)

任何人都能解释一下吗?
也许我不在

Gon*_*ing 7

实际上,您希望向字符串添加XML命名空间,以便可以解析Paragraph对象.喜欢:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Run Code Online (Sandbox Code Playgroud)

因为你真的只想要一个xmlns条目,所以用Section块包围它.您的完整工作字符串将是这样的:

richTextBox1.Xaml = "<Section xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><Paragraph>Blah</Paragraph></Section>";
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我将文本输入到RichTextBox(例如"Blah")中,然后查看textbox1.Xaml属性(总是首先使用工作方法进行调查以查看其中的内容).