Well, after one week of watching and reading tutorials I still couldn’t manage to pass xml data between pages. I had zero knowledge of c# at the beginning, i can understand a bit more know.
I would appreciate if you could guide me or at least tell me where to start. Ok, here is What I want to do and I couldn’t
For example; I have an xml data like this;
<document>
<car id="01">
<manufacturer>Ford</manufacturer>
<model>Mustang</model>
<year>1965</year>
<details>The Ford Mustang of 1965 was first unveiled bla bla for example....</details>
</car>
<car id="02">
<manufacturer>Chevrolet</manufacturer>
<model>Nova</model>
<year>1967</year>
<details>The Chevrolet Nova of 1967 was bla bla for example....</details>
</car>
<car id="03">.....
</document>
I want to show manufacturer and model inside the listbox the mainpage.xaml (It works ok)
TextBlock Text="{Binding manufacturer}"
TextBlock Text="{Binding model}"
When clicked on the model name i want to show year and details of the model in another page (details.xaml for example)
I was able to pass simple text with the method below but I couldn’t pass bindings and It didnt work for me. It just list details and year for all the cars not the specific one that i choose in the mainpage.
this.NavigationService.Navigate(
new Uri("/details.xaml?......
Thank you in advance. Sorry if I bothered you.
Instead of passing a long string of XML data between pages I’d just pass the car’s ID. Since you’re data binding to the ListBox on mainpage.xaml I’m assuming you have a class similar to the following:
Read the XML file on startup and create an
ObservableCollectionofCarobjects which is bound to theListBox. Then, in theTapgesture handler for theListBoxItemdo the following:Then, in the details page
OnNavigatedTomethod, simply find the correct car using theidand bind that object to the page’sDataContext.Note that
EscapeDataStringis not necessary if your IDs are always numeric. If you really want to pass all the XML data as is, you can do that as well by replacing the ID with the XML string data.