【问题标题】:How to programmatically switch to a different PanoramaItem?如何以编程方式切换到不同的 PanoramaItem?
【发布时间】:2011-03-06 00:52:48
【问题描述】:

注意:我已经看到 this 并没有回答问题。

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

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

【问题讨论】:

    标签: windows-phone-7 gestures panorama-control


    【解决方案1】:

    由于SelectedItem 和SelectedIndex 当前处于private set 规则下,因此您确实无法通过应用程序修改它们。但是,您可以更改 DefaultItem 属性:

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

    由于您将项目设置为列表中的第一个,因此会导致项目重新排列,但除此之外,这是一种可接受的方式,因为它实际上会将项目放在前面用户的。

    【讨论】:

      【解决方案2】:

      您可以更改 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

      【讨论】:

        猜你喜欢
        • 2013-05-17
        • 2011-07-13
        • 2010-11-08
        • 2012-06-20
        • 2020-05-27
        • 2019-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多