I use the Master/Details view from the UWP Community Toolkit and I am wrapping it in my "custom master/details view". This custom view should be able to print the current Detail
, so the DetailsTemplate
property on MasterDetailsView
. The problem is that I cannot pass a DataTemplate
to the UWP Toolkit Print Helper like this:
printHelper.AddFrameworkElementToPrint(NameOfMasterDetailsView.DetailsTemplate);
I tried to make a generic Page which has 2 DependencyProperties: 1) A data model, 2) a DataTemplate. This way I wanted to reuse the DataTemplate I used for the DetailsTemplate. I just passed those to a ContentPresenter:
<ContentPresenter ContentTemplate="{Binding MyDataTemplateProp}" Content="{Binding MyModelProp}"
(I also tried to use DataContext instead of Content).
Results stay the same: A blank page gets printed.
How can one print a DataTemplate
, populated with a data model?
More specific: how to print a detail page with the UWP Community Toolkit?
The problem is that I cannot pass a DataTemplate to the UWP Toolkit Print Helper
As your code line showed, you need to add a FrameworkElement
to print. DataTempalte
is inherit from FrameworkTemplate
it is not a FrameworkElement
, it just defined a template that doesn't indicate an area.
how to print a detail page with the UWP Community Toolkit?
You need to find the element that is responsible for the detail page section. If you check the MasterDetailsView
default template you will find that the detail page is inside a Grid
named DetailsPanel
. Try to find the DetailsPanel
element and pass it to print. For how to find this element you may need to use ViualTreeHelper
.