Unplanned
Last Updated: 02 Mar 2023 11:49 by ADMIN
Tursunkhuja
Created on: 07 Sep 2022 14:00
Type: Feature Request
3
WinUI3 Report Viewer - Replace Win32 print dialog with WinRT print API

Currently, the WinUI ReportViewer has a hard dependency on Windows due to the fact that the internals rely on the Win32 print dialog.

This means I cannot define the ReportViewer in a WinUI class library to be shared with multiple front-end WinUI projects. If you attempt to do this, there's an internal crash because the project cannot resolve  System.Windows.Forms.

This feature request is ask if you can replace the Win32 print dialog with the WinRT printing API. 

 

Research Note:  Here's a GitHub thread where Microsoft is discussing the topic Question: Printing in WinUI 3 Desktop · Issue #4419 · microsoft/microsoft-ui-xaml (github.com). Here's their current recommendation:

var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(App.StartupWindow);
var printMan = PrintManagerInterop.GetForWindow(hWnd);

await PrintManagerInterop.ShowPrintUIForWindowAsync(hWnd)

5 comments
ADMIN
Lance | Manager Technical Support
Posted on: 02 Mar 2023 11:49

Hi Tursunkhuja,

We have no new information to share at this time. When there is development on it, the status will change to "Planned", or "In Development", and you will be immediately notified via email of these changes.

To help set your expectations for a timeline, please let me share some extra information. I did start development on this when we first talked, which is when I initially intended to replace the dialog for WinUI. However, I discovered that the amount of work it will take to move off the Win32 printing canvas is very significant.

This is because the entire rendering system has to be rebuilt from the ground up in order to work with the UWP printing APIs (which is what WinUI uses). It's not just the print dialog, it's also connected to the print preview and rendering, which are real-world Report renderings on the user's target print selection. If you are curious what it takes to use the Windows 10 printing APIs, here are the docs and here are the demos.

Currently, there are some high priority items that must be complete before we can revisit this item, for example native .NET 67/8 VS2022 Designer support and .NET 7/8 rendering where there is no longer Windows drawing APIs present. This means I do not have a timeline that I can genuinely propose, nor can I guarantee it is worth migrating yet.

Fortunately, the current Win32 printing API implementation is battle tested and highly reliable with pixel-perfect results. We do hope to eventually move to Windows 11/12 visual features, but not at the cost of reliability or rendering. So, we're going to be extra careful moving forward with this, which is why it's still marked as Unplanned. If/when the time comes to work on this again, I will be sure to let you know by switching the status to "In Development".

I sincerely appreciate your understanding, let me know if there's anything else you'd like to know.

Regards,
Lance | Manager Technical Support
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.

 

[edit - added clarification, fixed grammar and punctuation]

Tursunkhuja
Posted on: 02 Mar 2023 04:48

Hi,

Any updates on this?

Telerik WinUI reportviewer still shows the old print dialog on windows 10:

 

When you plan to work on it? or is there any workaround to show new print dialog that winui shows on windows 11?

This is priont dialog shown by WinUI reportviewer on Windows 11:

 

Tursunkhuja
Posted on: 22 Sep 2022 06:20

Hi Lance,

I created WinUI3 single-project based .NET 6 which is working fine.

 

Thanks for suggestion,

ADMIN
Lance | Manager Technical Support
Posted on: 15 Sep 2022 21:40

Hi Tursunkhuja,

The migration to WinRT APIs is going to take a little while. It is a major change that will require research, development and testing before we make any kind of production-level switch.

Good News

I do have some great news for you however, I was able to get this working for you in a single-project .NET 6 WinUI3 project.

Prerequisite) Make sure you have the R3 2022 version of Telerik Reporting installed

I used this week's major R3 2022 update to base my dependencies on. You might be able to use R2 2022's, but I cannot confirm they work. You can update your local installation by running the Progress Control Panel app that should already installed on your machine (search the PC's Start Menu).

Once R3 2022 is installed, my project will work as-is. Go on to Step 1.

1) Download, extract and open the attached project in VS 2022

Note: If you have never used the Telerik NuGet server before, VS2022 is going to prompt you for credentials. Please enter your telerik.com username and password when it opens the credentials popup. Alternatively, you can use a Telerik NuGet Key in the nuget.config file I placed next to the sln file, but just giving VS your sign-in is much faster and works for future projects.

2) Rebuild to restore the NuGet packages and build the app

3) Deploy the project and you will see the following at runtime!

Note: Mine Window is in dark mode because my Windows 11 theme is set to dark, yours might be light mode.

Important Takeaway

Notice the following important considerations about the project

  • The OutputType is set to WinExe
  • The TFM is set to net6.0-windows10.0.19041.0
  • EnableMsixTooling is set to true
  • The three Framework References I added at the bottom are critical
  • I am using the Telerik.ReportViewer.WinUI NuGet Package
  • I am using the Telerik.WinUI.Controls DLL (I would normally use the NuGet package, but you only have a license for Reporting)

The biggest takeaway is adding those three FrameworkReferences, which allow the use of the Win32 Printing API:

	<ItemGroup>
		<FrameworkReference Include="Microsoft.WindowsDesktop.App.Wpf" />
	</ItemGroup>

	<ItemGroup>
		<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.19041.24" />
		<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.19041.24" />
	</ItemGroup>

Regards,
Lance | Manager Technical Support
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Attached Files:
Tursunkhuja
Posted on: 13 Sep 2022 04:01

Hi, 

Any updates on this?