-
Notifications
You must be signed in to change notification settings - Fork 7
ScopedButtonDisabler
HO-COOH edited this page Mar 22, 2026
·
2 revisions
| Name | IsDependencyProperty | Description |
|---|---|---|
N/A |
❌ | No corresponding WinUI3Package IDL runtimeclass was found for this component. |
#include <ScopedButtonDisabler.hpp>This is a simple header-only RAII-style class that disable a button in a scope.
When you attach a Click handler of a button and open a FilePicker, when user click fast enough, it will have 2 FilePicker opened at the same time, which is a source of logical bugs.
winrt::Windows::Storage::Pickers::FileOpenPicker picker;
picker.FileTypeFilter().Append(L"*");
auto file = co_await picker.PickSingleFileAsync();With ScopedButtonDisabler, it will disable the button inside this handler, preventing any logical bugs that might happens.
ScopedButtonDisabler disabler{ sender };
winrt::Windows::Storage::Pickers::FileOpenPicker picker;
picker.FileTypeFilter().Append(L"*");
auto file = co_await picker.PickSingleFileAsync();