修改目标页面

时间:2014-09-25 22:37:30

标签: c# windows-phone

所以我有一个longlistselector(在main中)有一个项目,还有一个" Detail-page" (全景页面)我想显示有关该特定项目的更多信息。我怎么能通过"信息,点击了什么项目以及应该加载详细信息页面中的内容? 也许是代码:

在主要我有

public partial class MainPage : PhoneApplicationPage
{

    //...
    public int ID = 0; //wrong, because my idea is false i guess

    //...


public MainPage()
{
    InitializeComponent();

    //...


private void example_Tap(object sender, EventArgs e) //example_tap is the eventhandler 
                                                     //when i tap an item on the longlistselector
    {
      //...

     var tb = sender as TextBlock;

     if (tb != null)
        {
            if (tb.Text == "Text of the first item in my list")
            {
                ID = 1; // My idea is to "pass" this int to the other page, 
                        // so i know what info to load
            }

            if (tb.Text == "Text of the second item in my list")
            {
                ID = 2;
            }
        //...and so on
        }  
    else
        {
            return;
        }      

    NavigationService.Navigate(new Uri("/Detailpage.xaml", UriKind.Relative));

    }

然后在Detailpage上我希望有这样的东西(这是一个新课程,这是我的问题)

 public partial class PanoramaPage : PhoneApplicationPage
 {

    public PanoramaPage()
    {
        InitializeComponent();
        //...



    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {

    ...
    if (ID == 1)
        {
            MyClass.LoadData_1(); // this loads information, 
                                  // that should "modify" the detailpage...

        }

    if (ID == 2)
        {
           MyClass.LoadData_2(); //in case, that the second item was tapped, 
                                 //the page should be filled with this information
        }

    //... and so on

    }
  }

所以我该怎么做? 非常感谢。为我的英语而战。

1 个答案:

答案 0 :(得分:0)

我认为您可以在URL上使用参数,在URL的末尾添加如下内容:

NavigationService.Navigate(new Uri("/Detailpage.xaml?ID=" + ID.ToString(), UriKind.Relative));

然后用

检索它
NavigationContext.QueryString.TryGetValue("ID", out ID);