Search code examples
windows-phone-7listboxtombstoning

Can't tombstone ItemsSource of a ListBox


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.


Solution

  • 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!