【发布时间】:2017-06-13 09:40:10
【问题描述】:
我需要将 DataTemplate 发送到新窗口以进行打印。
1) 我创建了一个通用窗口,我们将其命名为 PrintPreview,其中包含以下内容:
FlowDocument > BlockUiContainer > ContentControl(负责显示我将发送给它的DataTemplate)
问题是数据模板内的绑定不起作用。 (并非适用于所有情况)
例如: 我的应用程序中某处有这个数据模板
<DataTemplate x:Key="MyPrintPreview">
<DockPanel>
<TextBlock Text="{Binding SomeProperty1,RelativeSource={RelativeSource AncestorType=UserControl}}"></TextBlock>
<TextBlock Text="{Binding Source={StaticResource SomeViewModel},Path=SomeProperty2}"></TextBlock>
</DockPanel>
</DataTemplate>
上面的 DataTemplate 运行良好,并在我当前的 View (UserControl) 中显示了这两个属性 但是当我将此 DataTemplate 发送到新窗口 PrintPreview 时,我遇到了以下问题
第一个 TextBlock (SomeProperty1) 无法显示内容
第二个 TextBlock (SomeProperty2) 显示得很好!
我不知道如何使这项工作。或者如果我做错了?
【问题讨论】:
标签: wpf window datatemplate