dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.08k stars 1.17k forks source link

OpenFileDialog.ShowReadOnly does not work #6346

Open miloush opened 2 years ago

miloush commented 2 years ago

The OpenFileDialog ignores the ShowReadOnly property on the Vista code path.

Actual behavior:

No check box in the dialog.

Expected behavior:

A check box in the dialog as per documentation.

A dropdown option on the Open button would also be acceptable:

Minimal repro:

OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowReadOnly = true;
ofd.ShowDialog();
lindexi commented 2 years ago

Sorry, what is the Vista code path ?

miloush commented 2 years ago

There are two code paths for the file dialogs, one uses GetOpenFileName API while the other one uses IFileDialog API (introduced in Windows Vista):

https://github.com/dotnet/wpf/blob/3ccd6f5545fbebf775262af446f2aff819a2226c/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs#L823-L827

The legacy one is used on Windows XP only. The Vista one is used everywhere else:

https://github.com/dotnet/wpf/blob/3ccd6f5545fbebf775262af446f2aff819a2226c/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Microsoft/Win32/FileDialog.cs#L1830-L1833

.NET Core never supported Windows XP, unlike .NET Framework. However, you can still get the legacy behavior with .NET Core using compatibility settings:

image