我有一个存储为资源的FlowDocument(我需要生成的报告的模板)。这看起来效果很好,但是如果我命名这些元素,我就无法使用FindName()来获取对它们的引用。
这是资源字典:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FlowDocument x:Key="ReportStructure">
<Paragraph Name="ClientAddressParagraph" />
</FlowDocument>
</ResourceDictionary>
这是我的代码:
Dim _ReportResources = New ResourceDictionary() With {.Source = New Uri("/Reports/Statement.xaml", UriKind.Relative)}
Dim _FlowDocument As FlowDocument = _ReportResources.Item("ReportStructure")
Dim _Paragraph As Paragraph = _FlowDocument.FindName("ClientAddressParagraph")
' _Paragraph is Nothing (null) at this point.
有什么想法吗?我是否需要对流文档进行某种初始化,以便它注册命名元素的名称?