Hi am using XAML file given below.I want to Navigate Listbox selected item to another page.
private void NotchsList11_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var lb = sender as ListBox;
if (lb == null) return;
var articleSubItem = lb.SelectedItem as NotchSubItem;
if (articleSubItem == null) return;
App.CurrentArticle = articleSubItem;
NavigationService.Navigate(new Uri("/Test.xaml?selectedItem=" + articleSubItem.ArticleId, UriKind.Relative));
NotchsList11.SelectedIndex = -1;
}
To set details page
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
title.Text = App.CurrentArticle.Titles;
webBrowser.NavigateToString(App.CurrentArticle.FullContent);
}
base.OnNavigatedTo(e);
}
MainPage.xaml page
MainPage.xaml.cs
XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
var query = from l in xmlDoc.Descendants("Category")
select new Notch
{
name = (string)l.Attribute("name").Value,
Titles = l.Element("Articles").Elements("article")
.Select(s => s.Attribute("title").Value)
.ToList(),
Articles = l.Element("Articles").Elements("article")
.Select(article => new NotchSubItem
{
Image = article.Element("thumb_image").Element("image").Attribute("url").Value,
ArticleId = article.Attribute("articleid").Value,
FullContent = article.Element("FullContent").Value.ToString(),
Titles = article.Attribute("title").Value,
})
.ToList(),
Images = l.Element("Articles").Elements("article").Elements("thumb_image").Elements("image")
.Select(x => x.Attribute("url").Value).ToList(),
};
foreach (var result in query)
{
Console.WriteLine(result.name);
foreach (var detail in result.Titles.Zip(result.Images, (st, si) => string.Format("{0} {1}", st, si)))
{
Console.WriteLine(detail);
}
}
NotchsList11.ItemsSource = query;
}
catch(Exception e)
{
MessageBox.Show("Binding Failed");
}