您好,我想设置我的 silverlight 富文本框的 Xaml 属性。
this.Dispatcher.BeginInvoke(() =>
{
richTextBox1.Xaml = "<Paragraph>Blah</Paragraph>";
});
但是我得到以下异常..
System.ArgumentException: value
at System.Windows.Controls.RichTextBox.set_Xaml(String value)
有人能解释一下吗?
也许我不在
最佳答案
您实际上想为字符串添加一个 XML 命名空间,以便解析 Paragraph 对象。喜欢:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
因为您真的只需要一个 xmlns 条目,所以用一个 Section block 将其包围。您的完整工作字符串将是这样的:
richTextBox1.Xaml = "<Section xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><Paragraph>Blah</Paragraph></Section>";
为了解决这个问题,我在 RichTextBox 中输入了文本(例如“Blah”),然后查看了 textbox1.Xaml 属性(始终先使用工作方法进行调查,看看结果如何) .
关于c# - Silverlight RichtextBox Xaml 属性,无法设置值(异常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3856278/