Hi,
Welcome to Microsoft Q&A!
Maybe your image isn’t initialized or load completely when the preview window displays. Please refer to the following steps to resolve this issue.
1.Provide a Canvas
control and make it completely transparent(Opacity="0"), so that it doesn’t interfere with your UI.
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Canvas Name="MyCanvas" Opacity="0"/>
<Button x:Name="btnPrint" Click="btnPrint_Click" Content="Print" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center"/>
</Grid>
2.Add a PreparePrintContent
method and call it before the PrintManager.ShowPrintUIAsync
in the btnPrint_Click
event, as follows:
private async void btnPrint_Click(object sender, RoutedEventArgs e)
{
if (printDoc != null)
{
printDoc.GetPreviewPage -= OnGetPreviewPage;
printDoc.Paginate -= PrintDic_Paginate;
printDoc.AddPages -= PrintDic_AddPages;
}
this.printDoc = new PrintDocument();
printDoc.GetPreviewPage += OnGetPreviewPage;
printDoc.Paginate += PrintDic_Paginate;
printDoc.AddPages += PrintDic_AddPages;
PreparePrintContent(new PageToPrint());
bool showPrint = await PrintManager.ShowPrintUIAsync();
}
private void PreparePrintContent(Page pageToPrint)
{
var canvas=(Canvas)this.FindName("MyCanvas");
canvas.Children.Clear();
canvas.Children.Add(pageToPrint);
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
@Voytec-6484 PrintDoc is the PrintDocument Type object. As for "PrintDic_Paginate, PrintDic_AddPages", it is event handler, its event name isn't important, you could change it at will. You could compare this document.