Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #6346
Note: This PR is based on #7244. For review, see the individual commits, most notably 2e7aab3 and 74d617c. I can rebase if #7244 was not going in.
Description
Legacy (Windows XP) file dialog had a flag for showing a read-only checkbox, controlled by
OpenFileDialog.ShowReadOnly
. TheIFileDialog
API used since Vista does not have such flag, but the code has not been updated. As a result,ShowReadOnly
andReadOnlyChecked
properties do not work.This PR fixes the issue by matching the
IFileDialog
API fallback for legacy applications, i.e. by adding dropdown items to the OK button:ShowReadOnly = true; ReadOnlyChecked = false
:ShowReadOnly = true; ReadOnlyChecked = true
:The strings come from comdlg32.dll resources and will be in the language of the OS.
Implementation
In order to support the drop-down items on the OK button,
IFileDialogCustomize
andIFileDialogControlEvents
were implemented (together withIFileDialog2
for customizing the Cancel button). Controls can be added to all ofOpenFileDialog
,SaveFileDialog
andOpenFolderDialog
.For example,
gives:
A new
Microsoft.Win32.Controls
namespace is introduced. The public classes and members are as follows:New members on
CommonItemDialog
:CustomControls
OkButton
CancelButton
Remaining work:
Customer Impact
Not taking this fix leaves the read-only properties broken.
Furthermore, customers must rely on alternative solutions for file dialog controls. Many applications, from Notepad to Office to Visual Studio, use custom controls in their file dialogs.
Regression
No.
Testing
Manual testing using 7.0.100-rc.2.22477.23. Ensured
ReadOnlyChecked
is respected when dialog is shown and reflects the correct value when dialog is confirmed.Ensured all controls render, their state can be read after dialog is confirmed and is reverted when the dialog is cancelled. Limited testing of dynamically adding and removing items and changing controls' labels, visibility and status while the dialog is shown.
Risk
Medium. While the existing code already heavily depends on comdlg32.dll, this fix introduces an extra dependency on 3 of its resource strings. Alternatively these strings could be separately localized as part of WPF, but that might result in an inconsistencies since the language coverage of OS and WPF localization differs.
Furthermore, the controls introduce a possibility for the dialogs to be easily manipulated while they are being shown, which has not been possible before. While the existing properties are mostly read when the dialog is shown and updated when it is closed, a review should be done on whether they could and should be "live".
/cc @KirillOsenkov
Microsoft Reviewers: Open in CodeFlow