Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print Dialog Settings in Windows 11 22H2 Not Honored #8355

Open
miguelelvir opened this issue Oct 24, 2023 · 1 comment
Open

Print Dialog Settings in Windows 11 22H2 Not Honored #8355

miguelelvir opened this issue Oct 24, 2023 · 1 comment
Labels
Investigate Requires further investigation by the WPF team.

Comments

@miguelelvir
Copy link

miguelelvir commented Oct 24, 2023

Description

After the Windows 22H2 update, it seems that the modern UWP print dialog is used when trying to print XPS documents from a WPF application. This new dialog does not respect print settings that are set programmatically in the PrintTicket, such as page orientation.

Reproduction Steps

See sample repo here

Minimal repro code:

private void Print()
        {
            var localPrintServer = new LocalPrintServer();
            var printQueue = localPrintServer.DefaultPrintQueue;
            var printTicket = printQueue.DefaultPrintTicket;
            printTicket.PageOrientation = PageOrientation.Landscape;

            var dialog = new PrintDialog
            {
                PageRangeSelection = PageRangeSelection.AllPages,
                UserPageRangeEnabled = false,
                PrintQueue = printQueue
            };

            dialog.PrintTicket = dialog.PrintQueue.MergeAndValidatePrintTicket(dialog.PrintQueue.DefaultPrintTicket, printTicket).ValidatedPrintTicket;

            var allowPrint = dialog.ShowDialog().Value;
            if (allowPrint)
            {
                var xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue);
                xpsDocumentWriter.Write(CreateSomeContent(), dialog.PrintTicket);
            }
        }

Expected behavior

Print dialog should show landscape orientation when the printTicket page orientation is set to PageOrientation.Landscape

Actual behavior

Print dialog should show Landscape paper orientation when print ticket setting is set to landscape.

Regression?

Previous versions of Windows 10 show the legacy print dialog by default instead of the UWP dialog.

Known Workarounds

Registry key modification to disable UWP dialog

Impact

WPF application using print dialogs are not able to show preview or set printer settings. Additionally, printer settings are not remembered after dialog use.

Configuration

  • Which version of .NET is the code running on?
    Tried: .Net Framework 4.8.1 and .Net 6

  • What OS and version, and what distro if applicable?
    Windows 11 22H2

  • What is the architecture (x64, x86, ARM, ARM64)?
    x64

  • Do you know whether it is specific to that configuration?
    Appears to work in Windows 10 with old dialog. Also works in VMs (since the new UWP dialog does not get used in VMs)

Other information

  • Posting here in case there's a suggestion. Please advice if it should be a different repo and happy to adjust as needed.
  • Stackoverflow post
@MB-GP
Copy link

MB-GP commented Apr 8, 2024

Another workaround that works for me is to set the Application.MainWindow property to NULL before showing the print dialog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

3 participants