Hi,
I found the Simple navigation and the Passing data between pages tutorials helpful. I tried to create a list in one page and load the next page values based on the selection.
Here is my XML structure:
<Class>
<Classbook>
<Name>Database </Name>
<Text>XML XAML </Text>
<Reference>SQL SQLSErver </Reference>
</Classbook>
<Classbook>
<Name>Programming </Name>
<Text>VC# C# </Text>
<Reference>C++ VC++ </Reference>
</Classbook>
</Class>
I have a panorama page with a listbox which displays the class name but I want to display the booktext and reference in the next page in textblock . here is my code:
XDocument XMLFile=XDocument.Load(“Class.xml”);
// Set the data context of the listbox control to the sample data
var classes = from query in XMLFile.Descendants("Classbook")
select new Class {
Name = (string)query.Element("Name")
};
MainListBox.ItemsSource = classes;
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
// Handle selection changed on ListBox
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
// If selected index is -1 (no selection) do nothing
if (MainListBox.SelectedIndex == -1) return;
// Navigate to the new page
NavigationService.Navigate(new Uri("/DetailsPage.xaml?Class=" + Name, UriKind.Relative));
// Reset selected index to -1 (no selection)
MainListBox.SelectedIndex = -1; }
The second Page has this:
XDocument XMLFile = XDocument.Load(“Class.xml”);
//Page Title is a textblock displaying Class Name
PageTitle.Text = Name;
var Textbook= from query in XMLFile.Descendants(“Class”)
where query.Descendants(“Name”)=Name
select new Book {
Textbook =(string)query.Element("Text")
};
BookTitle.Text= Textbook;
var Reference = from query in XMLFile.Descendants("Book")
where query.Descendants("Name")=Name
select new Book {
Reference = (string)query.Element("Reference")
};
TextBlock1.Text = Reference;
Nothing is seen in the second page. Not even the page title. What am I doing wrong? Is the code correct? I really appreciate your help.