0

I am developing a program for the WIN UI. You must call ContentDialog and enter the user's password.

public async Task<bool> enterPasswordAsync(modeCheckPassword checkPassword)
{
    var content= new PasswordBox{Height = 32};
    ContentDialog dialog = new ContentDialog();
    dialog.XamlRoot = frame.XamlRoot;
    dialog.Content = content;
    dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style;
    dialog.Title = "Введите пароль";
    dialog.PrimaryButtonText = "Войти";
    dialog.SecondaryButtonText = "Отмена";
    dialog.DefaultButton = ContentDialogButton.Close;

    ContentDialogResult result = await dialog.ShowAsync();

    while (true)
    {
        if (await dialog.ShowAsync() == ContentDialogResult.Primary)
        {
            if (checkPassword.Invoke(content.Password))
                return true;
        }
        else
            return false;
    }
}

In debugging mode, I looked at what point the program was hanging. Freezes when calling ShowAsync.

When calling ContentDialog, my program freezes and does not process anything anymore. However, calling a simple ContentDialog does not cause any problems.

I watched the project on this site. https://xamlbrewer.wordpress.com/2022/03/09/a-dialog-service-for-winui-3/

I looked at the official Microsoft website https://learn.microsoft.com/ru-ru/uwp/api/windows.ui.xaml.controls.contentdialog?view=winrt-26100#derived_controls_with_winui_styles

3
  • I think a "proper pattern" would be that the "caller" of "EnterPassord" does the "retry" sequence; and not the "dialog routine" itself. The "routine" just returns "valid / not valid"; it should not / does not need to be aware of "retry counts", logging, and so forth: it just validates "one" attempt; that's it. The retry is a "higher authority". Commented Aug 5, 2024 at 15:17
  • Can't reproduce your issue. What do you mean by "Freezes"? Do you mean it crashes and throws exceptions? Can you make sure that the method is called on the Main Thread? Commented Aug 8, 2024 at 5:52
  • Could you please show a minimal, reproducible sample without private information? As far as the code snippet, the failure of checkPassword.Invoke(content.Password) will also cause a problem. Commented Aug 20, 2024 at 2:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.