如何引用我的 FlowDocument
我在 WPF 控件库中定义了 FlowDocument(添加新项...,FlowDocument - 是文件的根元素)。我打算在多个上下文中使用它,例如在用户控件或窗口中,在数据绑定和导出到 xps 的代码中引用,等等。但我不知道如何获取对实例的引用这份文件。它似乎没有在编译的程序集中创建对象。
更具体地说,这是我的问题
<MyUserControl ........ >
<FlowDocumentScrollViewer>
<!-- doesn't work --><namespaceRef:MyFlowDocument />
<FlowDocumentScrollViewer>
</MyUserControl>
I've defined a FlowDocument in a WPF control library (Add New Item..., FlowDocument -- is the root element of the file). I intend this to be used in several contexts such as in a user control or on a window, referenced in code for data-binding and export to xps, etc. But I can't figure out how to get a reference to an instance of this document. It doesn't seem to create an object in the compiled assembly.
More specifically, this is my problem
<MyUserControl ........ >
<FlowDocumentScrollViewer>
<!-- doesn't work --><namespaceRef:MyFlowDocument />
<FlowDocumentScrollViewer>
</MyUserControl>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的解决方案可能是将您的 FlowDocument 放入资源字典中,然后使用 x:Key 这样的
否则您必须设置 FlowDocument 来构建操作嵌入式资源并将其隐藏在代码后面,如下所示
Update
我认为如果您想研究它,可以使用 ObjectDataProvider 来加载 FlowDocument。不管怎样,ResourceDictionary 似乎是最简单的出路。
The easiest solution is probably to put your FlowDocument inside a Resource Dictionary and then use the x:Key like this
Otherwise you'll have to set the FlowDocument to build action Embedded Resource and lode it in code behind with something like this
Update
I think it might be possible to use an ObjectDataProvider to load the FlowDocument if you want to look into it. Anyway, a ResourceDictionary seems like the easy way out.