2011-03-06 39 views
2

注意:我已经看到this,它不回答这个问题。如何以编程方式切换到不同的PanoramaItem?

我对我的应用程序有第一次运行体验,向用户介绍解释应用程序的几个不同选项。如果他们选择其中一个选项,我想向他们展示处理该特定功能的PanoramaItem。它恰好是项目#3。

所以,Panorama.SelectedItem是只读的。有其他方法可以做到吗?如果不是,我可以通过模拟某些手势输入来伪造它吗?如何做到这一点?

回答

2

由于SelectedItemSelectedIndex目前在private set规则下,所以您无法通过应用程序修改它们。但是,您可以更改DefaultItem属性:

<PANORAMA_CONTROL>.DefaultItem = <PANORAMA_CONTROL>.Items[1]; 

这将导致项目是有点重排的,因为你设置的项目是在列表中的第一个,但比它是一个可以接受的方式等要做到这一点,因为它实际上会将物品带到用户面前。

1

您可以更改DefaultItem。

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     string selected = String.Empty; 

     //check to see if the selected parameter was passed. 
     if (NavigationContext.QueryString.ContainsKey("selected")) 
     { 
      //get the selected parameter off the query string from MainPage. 
      selected = NavigationContext.QueryString["selected"]; 
     } 

     //did the querystring indicate we should go to item2 instead of item1? 
     if (selected == "item2") 
     { 
      //item2 is the second item, but 0 indexed. 
      myPanorama.DefaultItem = myPanorama.Items[1]; 
     } 
     base.OnNavigatedTo(e); 
    } 

下面是我为不同目的所做的示例,但它具有此功能。 http://dl.dropbox.com/u/129101/Panorama_querystring.zip

相关问题