Print Dialog Settings in Windows 11 22H2 Not Honored
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### 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](https://github.com/miguelelvir/win11-print-dialog-bug/blob/main/Win11Print/MainWindow.xaml.cs)
Minimal repro code:
```csharp
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](https://answers.microsoft.com/en-us/windows/forum/all/printing-from-win32-application-new-after/881db830-6c42-450c-bb93-0a08f62ca647?page=5) 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](https://stackoverflow.com/questions/76729125/how-can-we-set-the-settings-for-printing-in-the-new-print-preview-of-windows-11)
Contributor guide
Assessment
This issue has not been assessed yet.