-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CanCloseAsync does not work properly with WindowManager #585
Comments
Thanks for the bug report, is this from the latest source? I've fixed up one bug like this already. |
Yes, it is in the latest source.
|
After changing the WindowManager.Closing method as I posted above, the CanCloseAsync works. But that causes other odd issues when the dialog is closed. I tried to change WindowManager.Closing as below, now everything seems fine, no odd issue happens. I have no clue why it works ^_^
|
I found the reason that causes weird errors when the Closing event uses async. It is the Screen.TryCloseAsync method.
If I modify it as below, the errors are gone
The WindowManager.Closing is now like below. Please notice
|
Pushed some changes to WindowManager that fixes my copy of your example (once Would love you to check. |
I try the newest code and I see the exception below when TryCloseAsync(false) is called. It is strange that TryCloseAsync(true) works fine. I attach the sample project underneath. The test code is in MyDialogViewModel.cs.
|
Thanks, I'll take a look, assume the behavior of the dialog is correct? |
This should now be resolved. |
After updating the newest code, I see the exception does not happen in the sample above (Test.Wpf.zip). But if I change the CanCloseAsync as below, another exception happens again.
This error can be resolved by putting
|
#596 has been submitted to fix this in a different way, will look over possible solutions soon. |
Merged #596 to resolve this issue. |
I updated the newest source and tested with the project in Test.Wpf.zip above. The
I see the Accept and Cancel buttons work as expected. But the problem comes when the user closes the dialog by clicking the close icon [x] on the title bar or pressing Alt+F4. In this case the user has to click or press TWICE to close the dialog. The first click or press has no effect. It seems that is due to I note that |
I realise what it does, and yes the current behavior isn't ideal (and will be fixed). |
Pushed an approach using |
Assume this is resolved @hoangcuongvn ? |
Nigel, this issue still exists. If This issue can be resolved if the
|
I can't recreate this issue on my machine using your example. public class MyDialogViewModel : Screen
{
public async void DoAccept()
{
await TryCloseAsync(true);
}
public async void DoCancel()
{
await TryCloseAsync(false);
}
public override Task<bool> CanCloseAsync(CancellationToken cancellationToken)
{
return Task.FromResult(true);
}
} |
Your code above is correct. The issue only happens when the user clicks on the Cancel button. I record a video of reproducing the exception in the link below: |
I still can't; recreate this problem with the current version of the code. |
It is quite strange. I am sure that I was using the latest source code. Please have a look in this new video to check if anything is missed? |
Nothing stands out as wrong, you're clearly rebuilding the source which was main thing I was looking for. I'm curious if you have the latest version, the commit c656c51 has a fix for |
Yes, the source I was using is the latest and it does include the c656c51 fix. |
Not sure what's going on then. Will take another look at it once I'm back from Easter break. |
Hi Nigel, have you re-checked this issue? I am using CM in my real Wpf projects. In simple projects which have less UI interaction, the error does not happen. But in more complicated projects with more UI interaction, this error happens. If I modify the Screen.TryCloseAsync as I posted above, the error no longer happens. |
I haven't been able to recreate the issue with the current version of the code. |
I created a full solution in the link below. Can you download and run it? The dialog has 2 button Accept and Cancel. Please click on the Cancel button. Does the error happen? |
I create a sample to reproduce the issue. You will see MyDialogViewModel has its CanCloseAsync returns false but its view/dialog is still closed.
https://drive.google.com/open?id=1e9Qz_iFfZkTpYe2jhlBYZm6vHzkn9f9L
This issue is related to the Window.Closing event which does not work properly with async. I found a workaround.
https://stackoverflow.com/questions/49012892/cannot-use-async-in-closing-method
I suggest to change the WindowManager.Closing method as below
The text was updated successfully, but these errors were encountered: