0

I've set up a viewmodel to bind a listcontrol to an ObservableCollection in my program. A UI control on the page adds and deletes objects to the collection, which works fine as the list is automatically updated.

After App-Switching and returning to the app, the buttons adds the objects, but the bindings seem to be lost. Any idea how I can maintain this even after returning? I don't really see the need to rebind the object (after defining it in XAML). Is there any way to foolproof this pattern, and ensure the bindings aren't lost upon returning to the app?

The XAML looks like this, but it's inside a UserControl - forgot to mention that

ItemsControl x:Name="PartyCollection" ItemTemplate="{StaticResource PartyCollectiontemplate}" ItemsSource="{Binding RoomParty, Source={StaticResource FormControlVM}}"

the codebehind looks like this

public class FormControlVM : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    public ObservableCollection<Party> RoomParty
    {
        get
        {
            return App.appData.currentChoices.roomParty;
        }
        set
        {
            App.appData.currentChoices.roomParty = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("RoomParty"));
        }
    }
}
Jasperan
  • 2,154
  • 1
  • 16
  • 40
Jay Kannan
  • 1,372
  • 3
  • 14
  • 30
  • Do you have a simple repro? (There are lots of ways you could be doing what you describe.) – Matt Lacey Feb 02 '12 at 11:16
  • I'm surprised that it doesn't handle it internally. do you thin I should rebind the values? – Jay Kannan Feb 02 '12 at 18:03
  • I just found out that it might be because I'm serializing/deserializing App.appData.CurrentChoices , and i'm not sure if ObservableCollection is serializable. any advice? – Jay Kannan Feb 02 '12 at 18:23
  • It also looks like I should use CollectionChanged instead of PropertyChanged, but i'm not finding much help online. – Jay Kannan Feb 02 '12 at 19:39

0 Answers0