Julian de Wit
Julian de Wit

Reputation: 3094

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

Upvotes: 1

Views: 3081

Answers (1)

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93561

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

Upvotes: 7

Related Questions