我创建了一个ContentDialog,其中包含一个TextBox,用户可以在其中输入SMS代码。当此代码正确时,我需要用户导航到主页。
问题是Navigate.Frame在此上下文中不存在。
拜托,我做错了什么?
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"]);
}
答案 0 :(得分:0)
最后,经过一些研究,我找到了答案。
必须在课程开头实例化RootFrame。
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)
{
}
}