5

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.

1
  • I have the same prob. but no one has given the appropriate answer yet. if you have solved it ... then plz share it here. :) +1 Mar 1, 2016 at 5:02

1 Answer 1

6

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.