Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can´;t从Windows Phone 8.1内容对话框导航_C#_Windows Phone 8.1 - Fatal编程技术网

C# Can´;t从Windows Phone 8.1内容对话框导航

C# Can´;t从Windows Phone 8.1内容对话框导航,c#,windows-phone-8.1,C#,Windows Phone 8.1,我创建了一个ContentDialog,其中包含一个文本框,用户可以在其中输入SMS代码。当代码正确时,我需要用户导航到主页 问题是导航。此上下文中不存在框架 拜托,我做错什么了 private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { String _confirmaSms = "https:/

我创建了一个ContentDialog,其中包含一个文本框,用户可以在其中输入SMS代码。当代码正确时,我需要用户导航到主页

问题是导航。此上下文中不存在框架

拜托,我做错什么了

 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"]);



    }

经过研究,我终于找到了答案

必须在类的开头实例化根框架

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)
    {

    }




}