简体   繁体   中英

How to navigate to another Page from a User Control in Windows Phone 8.1

I have searched for this, but wasn't able to find anything directly related to the Windows Phone 8.1 Environment, please let me know if there is a link available as I would have thought this would be a common question..

I am trying to navigate to another page from within a UserControl when an Item in a list is tapped, however, I am having troubling getting Parent page's Frame so I can navigate.

Essentially, I am trying to do this within the User Control.

 private void lstFoo_ItemClick(object sender, ItemClickEventArgs e)
    {
        Page parentPage = this.Parent as Page; //Returns null

        if (parentPage != null)
        {
            parentPage.Frame.Navigate(typeof(BarPage), e.ClickedItem);
        }
    }

The User Control will be used on multiple pages, and all with the same result, however I just can't work out how to get that Navigate to work and then pass the parameter along. Any help would be appreciated..

Thanks.

If you are using standard WP template with one Frame set as Content of your Window then it should be possible to do it like this:

private void lstFoo_ItemClick(object sender, ItemClickEventArgs e)
{
    (Window.Current.Content as Frame).Navigate(typeof(BarPage), e.ClickedItem);
}

Only look out with passing this parameter - if it's not serializable then when your app will be suspended then SuspensionManager will throw exception.

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