Pergunta

I am building an app for WP8 with CustomMessageBox. The content of the customMessageBox includes a textBox and LeftButton. I want the customMessageBox remain open until user writes something in the textBox and it is varified. Here is some code:

this.Dismissed += async (sender, dismissedEvent) =>
            {
                switch (dismissedEvent.Result)
                {
                    case CustomMessageBoxResult.LeftButton:                       
                        this.isSaved = await CreateUser();
                        break;
                    case CustomMessageBoxResult.None:
                        break;
                    case CustomMessageBoxResult.RightButton:
                        break;
                    default:
                        break;
                }
            };

I created boolean variable isSaved for the following code:

this.Dismissing += (sender, e) =>
                {
                    if (!this.isSaved)
                    {
                        e.Cancel = false;
                    }
                };

But it doesn't work - maybe e.Cancel is for sth else, although I can't find any docs about it. The method CreateUser() validates the input and saves it to the db.

I searched in the Internet for the solution but couldn't find anything, if You could help me or show me where I can find the solution, I would greatly appreciate it. Thank You in advance!

Foi útil?

Solução

What about this...

    private async void CmbDismissing(object sender, DismissingEventArgs e)
    {
        if (e.Result == CustomMessageBoxResult.LeftButton)
        {
            // still open
            e.Cancel = true;

            bool isSaved = await this.CreateUser();

            // close
            if (isSaved)
            {
                ((CustomMessageBox)sender).Dismiss();
            }
        }
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top