简体   繁体   中英

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 System.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 (eg "Blah") and then viewed the textbox1.Xaml property (always investigate using working methods first to see what comes out of it) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM