microsoft / microsoft/microsoft-ui-xaml

Proposal: Synchronous ContentDialog

Open
#10,436 0 comments 1 reaction 0 assignees View on GitHub
area-Dialogs feature proposal
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

The idea is that non WinUI3 apps that would switch to WinUI are using MessageBox and DialogBox which are blocking calls; The caller expects a return value.

Trying to create another message loop doesn't work, it crashes on return:

```
void MainPage::ShowDialogBlocking(winrt::Microsoft::UI::Xaml::Window const& mainWindow)
{
auto dialog = ... // ContentDialog
auto dispatcherQueue = mainWindow.DispatcherQueue();

auto as = dialog.ShowAsync();
as.Completed([&](auto const&, auto)
{
dispatcherQueue.EnqueueEventLoopExit();
});

dispatcherQueue.RunEventLoop();
}
```

If this could work then non WinUI3 apps will have an easier time in transiting to WinUI3.

Note that the following seems to work but I'm not sure it is reliable.

```
void MainPage::ShowDialogBlocking()
{
auto dialog = ... // ContentDialog
ContentDialogResult res;
bool Completed = 0;
auto as = dialog.ShowAsync();
as.Completed([&](auto const& sender, auto)
{
res = sender.as>().GetResults();
Completed = 1;

});

while (!Completed)
{
MSG msg;
if (GetMessage(&msg, 0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing ContentDialog.ShowAsync, DispatcherQueue.RunEventLoop, and the GetMessage loop shown in the issue, along with how ContentDialogResult is retrieved. Determine whether a supported synchronous ContentDialog API can return a result without crashing or introducing unreliable nested message-loop behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.