代码之家  ›  专栏  ›  技术社区  ›  Julian de Wit

Silverlight RichTextBox XAML属性,无法设置值(异常)

  •  1
  • Julian de Wit  · 技术社区  · 15 年前

    嗨,我想设置我的Silverlight RichText框的XAML属性。

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

    但是,我得到了以下例外。

    System.ArgumentException: value
       at System.Windows.Controls.RichTextBox.set_Xaml(String value)
    

    有人能解释一下吗?
    也许我不在

    1 回复  |  直到 15 年前
        1
  •  7
  •   iCollect.it Ltd    15 年前

    实际上,您希望向字符串中添加一个XML命名空间,以便解析Paragraph对象。像:

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

    因为您只需要一个xmlns条目,所以用一个节块将其包围。您的完整工作字符串如下:

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

    为了解决这个问题,我在richtextbox中输入了文本(例如“blah”),然后查看了textbox 1.xaml属性 (总是先使用工作方法进行调查,看看结果如何) .