Unplanned
Last Updated: 22 Sep 2022 06:20 by Tursunkhuja
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)

3 comments
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?