最近在使用RichTextBox时,因为是MVVM模式,要绑定它的Document,但Document不是依赖属性,就重新写了个类BindableRichTextBox,继承自RichTextBox。起初一切顺利,但后面发现在设计视图时,总是报下面这个错误:

ArgumentException: Document 已属于另一 RichTextBox;

如果是英文版vs的话,应该报的是

Document already  belongs to another RichTextBox;

查阅了很多官方文档,最后发现是因为不能共享实例。

故在类声明出,增加标记:[PartCreationPolicy(CreationPolicy.NonShared)]

命名空间:   System.ComponentModel.Composition
程序集:  System.ComponentModel.Composition(位于 System.ComponentModel.Composition.dll))

 

相关文章:

  • 2022-12-23
  • 2021-09-27
  • 2021-11-02
  • 2021-11-02
  • 2021-04-06
  • 2021-09-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
  • 2022-01-22
  • 2021-06-15
相关资源
相似解决方案