Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
currently im having troubles in keeping the collections in the list in the mvvm, every time that i navigate away and return to a page, the list keeps getting empty. how am i going to deal with this? can someone help me with this? The Model: I have not implemented the others yet because i cant add items to the list

The ViewModel:

class CartingDataSource : BindableBase
{
public ObservableCollection<CartData> _cartData;
 
public ObservableCollection<CartData> CartData
        {
 
         get {
 
               if (_cartData == null)
                {
                    _cartData = new ObservableCollection<CartData>();
                }
             return _cartData;
             }
        set {
 
                SetProperty(ref _cartData, value);
           }
        }
 

 

        private DelegateCommand _addItemCommand;
        public ICommand AddItemCommand
        {
            get
            {
                if (_addItemCommand == null)
                {
                    _addItemCommand = new DelegateCommand(AddToCart);
                }
                return _addItemCommand;
            }
        }
       public void AddToCart() {
 
       CartData.Add(new CartData 
         { 
            Cakename = "Black Forest", Cakeprice = 104 });
}
 
                   }


i have already asked in the stackoverflow but no proper answer yet. can you please help me? this is my second post in here thank you!
Posted
Updated 4-Mar-14 20:34pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900