MessageBox.Avalonia
MessageBox.Avalonia copied to clipboard
It can not click when box.ShowAsync().Result;
it seem that loop
Any more description? Do you call it in an override window OnClosing event handler function?
I think i found his problem:
I've setup a simple button in my main window:
<Button
Width="32"
Height="32"
Cursor="Hand"
HorizontalAlignment="Stretch"
Click="Button_Click">
</Button>
private void Button_Click(object? sender, RoutedEventArgs e)
{
var box = MessageBoxManager
.GetMessageBoxStandard("Caption", "Are you sure you would like to delete appender_replace_page_1?",
ButtonEnum.YesNo);
_ = box.ShowAsync().Result; // <- Issue
}
Issue:
When the button is clicked, the application thread gets blocked.
Observed Behavior:
- The message box becomes unresponsive.
- The main window also becomes unclickable.
- The application is effectively frozen.
Using async with await seems to resolve the problem
private async void Button_PlayStopClick(object? sender, RoutedEventArgs e)
{
var box = MessageBoxManager
.GetMessageBoxStandard("Caption", "Are you sure you would like to delete appender_replace_page_1?",
ButtonEnum.YesNo);
_ = await box.ShowAsync();
}
That's typical "feature" of gui frameworks https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html