开发者

Silverlight RichtextBox Xaml Property, cannot set value (exception)

Hi I want to set the Xaml property of my silverlight richtext box.

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

However I get the following exception..

System.ArgumentException: value
   at Syst开发者_运维百科em.Windows.Controls.RichTextBox.set_Xaml(String value)

Can anybody explain this ?

Maybe I am not in the


You actually want to add an XML namespace to the string, so that the Paragraph object can be resolved. Like:

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

As you really only want a single xmlns entry, surround it with a Section block. Your complete working string will be this:

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

To work this out, I entered text into a RichTextBox (e.g. "Blah") and then viewed the textbox1.Xaml property (always investigate using working methods first to see what comes out of it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜