How to navigate to different pivot items in WP7

我与影子孤独终老i 提交于 2019-12-31 02:15:48

问题


I have a panorama page in which I have 3 buttons. I have added a pivotpage to the same project which has 3 pivot items. When I click Button 1 in panorama page it should goto the first pivot item in pivot page and when I click button 2 in panorama page it should goto the second pivot item in pivot page. How can I achieve this navigation? Please let me know.


回答1:


You could pass a querystring to the pivot page and then, once the pivot is loaded, set the index to the relevant page. As a basic example, you can handle button 2 like this:

NavigationService.Navigate(new Uri("/myPivotPage.xaml?id=2", UriKind.Relative));

Then in your pivot page's Loaded event, you can set the jump to the index like this:

string pivotIndex = "";

if(NavigationContext.QueryString.TryGetValue("id", out pivotIndex))
{
    //-1 because the Pivot is 0-indexed, so pivot item 2 has an index of 1
    myPivot.SelectedIndex = Convert.ToInt32(pivotIndex) - 1;
}


来源:https://stackoverflow.com/questions/9284334/how-to-navigate-to-different-pivot-items-in-wp7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!