修改目标页面
本文关键字:目标 修改 | 更新日期: 2023-09-27 18:24:39
所以我有一个包含项目的长列表选择器(在main中)和一个"详细信息页面"(全景页面),我想在其中显示有关该特定项目的更多信息。我如何"传递"信息,点击了什么项目,应该加载"详细信息"页面中的什么?所以也许代码是:
总的来说,我有
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));
}
然后在细节页面上,我想要这样的东西(当然这是一个新的类,这是我的问题)
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
}
}
那么我该怎么做呢?非常感谢。我的英语sry。
我认为你可以在URL上使用参数,在URL的末尾添加一些类似的内容:
NavigationService.Navigate(new Uri("/Detailpage.xaml?ID=" + ID.ToString(), UriKind.Relative));
然后用检索
NavigationContext.QueryString.TryGetValue("ID", out ID);