I have one application that has several pages; therefore, I want user to navigate to and back from one page to another with the some data sent back and forth. I could navigate to next page with some specific data by using
NavigationService.Navigate(new Uri("/All Files/Product Files/Product List.xaml?pro_cate_id="+(lstb_prod_cate.SelectedItem as ProductsDry).DryCategoryId, UriKind.Relative));
On next page "Product List.xaml", it can receive data sent to it and do query fine. However, on "Product List.xaml" I put one button and set its event to "NavigationService.GoBack()" so user can press to go to the previous page. At this point, when it is back to the previous page, I got an error at
private void lstb_prod_cate_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(new Uri("/All Files/Product Files/Product List.xaml?pro_cate_id="+(lstb_prod_cate.SelectedItem as ProductsDry).DryCategoryId, UriKind.Relative));
}
This is the first page that it will send data to next page
Product Category.xmal.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Xml.Linq;
using App_Skin_Test_Final_.All_Files.Database_XML;
namespace App_Skin_Test_Final_.All_Files.Product_Files
{
public partial class Product_Category : PhoneApplicationPage
{
public Product_Category()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MessageBox.Show("OnNavigateTo");
base.OnNavigatedTo(e);
// Do something when the page first loaded
}
private void lstb_prod_cate_Loaded(object sender, RoutedEventArgs e)
{
XDocument xd = XDocument.Load("All Files/Database XML/ProductsDry.xml");
var data = from q in xd.Descendants("DryCategory")
orderby q.Attribute("DryCategoryName").Value
select new ProductsDry
{
DryCategoryName = q.Attribute("DryCategoryName").Value,
DryCategoryId=q.Attribute("DryCategoryId").Value
};
// MessageBox.Show();
lstb_prod_cate.DataContext = data;
}
private void lstb_prod_cate_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(new Uri("/All Files/Product Files/Product List.xaml?pro_cate_id="+(lstb_prod_cate.SelectedItem as ProductsDry).DryCategoryId, UriKind.Relative));
}
}
}
And this is a next page "Product List.xaml.cs" that it will receive data and can press button to go back
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Xml.Linq;
using App_Skin_Test_Final_.All_Files.Database_XML;
using System.Windows.Media.Imaging;
namespace App_Skin_Test_Final_.All_Files.Product_Files
{
public partial class Product_List : PhoneApplicationPage
{
string pro_cate_id;
public Product_List()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.TryGetValue("pro_cate_id", out pro_cate_id))
{
}
}
private void lst_product_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show(pro_cate_id);
XDocument data = XDocument.Load("All Files/Database XML/ProductsDry.xml");
var productListData = from q in data.Descendants("DryCategory")
from itemDry in q.Elements("ItemDry") // mean: itemDry in in DryCategory
where q.Attribute("DryCategoryId").Value == pro_cate_id
select new ProductsDry
{
ItemDryName = itemDry.Attribute("ItemDryName").Value,
ItemDryImage=getImage(itemDry.Attribute("ItemDryImage").Value),
ItemDryId=itemDry.Attribute("ItemDryId").Value
};
lst_product.DataContext = productListData;
// NavigationService.GoBack();
}
private System.Windows.Media.ImageSource getImage(string p)
{
return new BitmapImage(new Uri(p, UriKind.Relative));
}
private void lst_product_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(new Uri("/All Files/Product Files/Product Detail.xaml?itemId="+(lst_product.SelectedItem as ProductsDry).ItemDryId,UriKind.Relative));
}
private void btnGoBack_Click(object sender, RoutedEventArgs e)
{
if (this.NavigationService.CanGoBack)
{
this.NavigationService.GoBack();
}
}
}
}
Please, can anyone help me with this error? Thanks