简体   繁体   English

给定参数时 Frame.Navigate 失败

[英]Frame.Navigate failing when parameter is given

When I attempt to send parameters along with Frame.Navigate method it fails with "NullReferenceException".当我尝试将参数与 Frame.Navigate 方法一起发送时,它会因“NullReferenceException”而失败。

This is the method with frame.navigate method这是带有 frame.navigate 方法的方法

    private void remotesList_ItemClick(object sender, ItemClickEventArgs e)
    {
        string args = JsonConvert.SerializeObject(e.ClickedItem.ToString());
        this.Frame.Navigate(typeof(RemoteContent),args);

    }

This is the code on receiving page这是接收页面上的代码

        protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        string args = JsonConvert.DeserializeObject<string>((string)e.Parameter);
        base.OnNavigatedTo(e);
    }

Is there anything wrong with the code or any other way to send arguments with navigate method?使用导航方法发送 arguments 的代码或任何其他方式有什么问题吗?

For anyone running into this same issue.对于遇到同样问题的任何人。 The problem was that OnNavigatedTo runs after the initialization method (public RemoteContent() in my case).问题是 OnNavigatedTo 在初始化方法之后运行(在我的例子中是 public RemoteContent())。 I tried to use the parameter given in the Frame.Navigate inside the initialization method of RemoteContent.我尝试在 RemoteContent 的初始化方法中使用 Frame.Navigate 中给出的参数。 Because OnNavigatedTo was called after this, the value was used before it could be assigned.因为在此之后调用了 OnNavigatedTo,所以在分配之前使用了该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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