简体   繁体   中英

Can´t navigate from Windows Phone 8.1 Content Dialog

I created a ContentDialog that contains a TextBox where the user enter a SMS code. When this code is right, I need the user navigate to a Home Page.

The problem is Navigate.Frame does not exist in this context.

Please, What Am I doing wrong?

 private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
    {

        String _confirmaSms = "https://example.com";
        RestClient client = new RestClient();
        string msisdn = PrimaryButtonCommandParameter.ToString();
        string codigoConfirmacao = txtCodigoConfirmacao.Text;

        Usuario usuario = new Usuario()
        {
            msisdn = msisdn,
            codesms = codigoConfirmacao
        };

        string output = JsonConvert.SerializeObject(usuario);

        //Debug.WriteLine(output);

        string response = await client.RestConnection(_confirmaSms, "POST", output);
        JObject responseObj = JObject.Parse(response);
        JObject resultObj = (JObject)responseObj["result"];
        string result = resultObj["codesms"].ToString();

        if (usuario.codesms.ToString() == result && result != null)
        {
           //code to navigate
        }
        else
        {
            //code to navigate to other page
        }

        Debug.WriteLine(resultObj["ltoken"]);



    }

Finally, after some research, I found an answer.

Have to instantiate the RootFrame at the beginning of class.

public sealed partial class ConfirmaSMS : ContentDialog
{
    Frame rootFrame = Window.Current.Content as Frame;

    public ConfirmaSMS()
    {
        this.InitializeComponent();
    }

    private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
    {

        String _confirmaSms = "https://www.Example.com";
        RestClient client = new RestClient();
        string msisdn = PrimaryButtonCommandParameter.ToString();
        string codigoConfirmacao = txtCodigoConfirmacao.Text;

        string output = JsonConvert.SerializeObject(usuario);

        //Debug.WriteLine(output);

        string response = await client.RestConnection(_confirmaSms, "POST", output);
        JObject responseObj = JObject.Parse(response);
        JObject resultObj = (JObject)responseObj["result"];
        string result = resultObj["codesms"].ToString();

        if (usuario.codesms.ToString() == result && result != null)
        {
            Debug.WriteLine(result.ToString());
            rootFrame.Navigate(typeof(HomePage));
        }
        else
        {
            confirmaSMS.SecondaryButtonCommandParameter = false;
            confirmaSMS.Hide();
        }

        Debug.WriteLine(resultObj["ltoken"]);



    }

    private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
    {

    }




}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM