0

I have a ListBox populated with data coming from XML. Fine so far, the problem is that I get some errors when I try to tombstone it.

protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
        State["listbox1"] = listBox1.ItemsSource;
    }

Then:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        if (State.ContainsKey("listbox1"))
        {
            listBox1.ItemsSource = (IEnumerable)State["listbox1"];
        }
    }

When I hit the start button I already get an error. The App.xaml.cs opens and the line below becomes yellow

System.Diagnostics.Debugger.Break();

I've also used tombstoning helper but it did not return the items in my listbox.

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85
Diego Vin
  • 193
  • 2
  • 12

1 Answers1

0

What is the listbox bound to? And what error are you seeing?

If it's a DataServiceCollection, you may have tracking turned on & you cannot put it flatly in Isolated Storage or State dictionaries. Should be fine if using ObservableCollection.

Thanks!

Sam Basu
  • 966
  • 6
  • 14
  • No error is shown, only that line turns yellow. The listbox is bound to data coming from a xml: var tab = from c in xml.Descendants("tbody").Descendants("tr") ... listBox1.ItemsSource = tab; – Diego Vin Nov 30 '11 at 00:16
  • How about you try serializing "tab" on its own. Can you put that in State dictionary? – Sam Basu Nov 30 '11 at 01:32
  • I tryed to, but I can not access it. Its is a local variable inside an openReadCompleted method... – Diego Vin Nov 30 '11 at 11:49
  • Seems like I cant do anything like this: State["list"] = ienumerable type variable. ANy ideias would be nice – Diego Vin Nov 30 '11 at 13:53
  • Yes I should be able to. Let's do this .. define an ObservableCollection at class level .. where T could be generic like string or a custom class. Then fill up the collection on your Completed method & then try putting the collection in State. – Sam Basu Nov 30 '11 at 13:59
  • I defined an ObservableCollection variable, but linq to xml returns me an ienumerable. So when I try to fill it, i get a invalid cast exception... – Diego Vin Nov 30 '11 at 15:43
  • Ok wait .. ObservableCollection already implements the IEnumerable interface, so you are double-doing it. Let's make it simple .. so your LINQ returns an IEnumerable or IEnumerable, right? You should be able to tombstone the IEnumerable directly. Let's try that. – Sam Basu Nov 30 '11 at 19:33
  • my LINQ returns an IEnumerable, but When i try: ObservableCollection variable = linq statement I get an cast error... – Diego Vin Nov 30 '11 at 21:02
  • Simply put the IEnumerable in State. – Sam Basu Dec 01 '11 at 01:42
  • I´ve already tried that, but when I navigate to my app it does not fill the list... – Diego Vin Dec 01 '11 at 03:39
  • Wel I Will try that too, but I found the answers using Isolated Storage instead of State. [link]http://stackoverflow.com/questions/8329483/isolated-storage-security-exception-on-windows-phone/8336519#8336519 THX! – Diego Vin Dec 02 '11 at 13:06