tags:

views:

45

answers:

1

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

+1  A: 

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\"&gt;&lt;Paragraph&gt;Blah&lt;/Paragraph&gt;&lt;/Section&gt;";

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).

Enough already
Thanks ! Indeed the MS page did not mention this at all..
Julian de Wit