Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys i was able to add items using this method
C#
public ObservableCollection<CartData> cartData
     {

         get
         {
             if (App.Current._cartData == null)
             {
                 App.Current._cartData = new ObservableCollection<CartData>();

             }


             return App.Current._cartData;

         }
         set
         {

             SetProperty(ref App.Current._cartData, value);
         }
     }

public CartData(){

cartData.Add(new CartData { Cakename = this.CakeName, Cakeprice = App.Current.cakeprice,ImagePath=bitmapimage,Caketype=App.Current.caketype,Cakesize=App.Current.cakesize });


}


it is binded to the listview, now im trying to remove the item if certain item is selected and pressed a button. How do i know the Index of the selected item in the list?
Posted

Add a second property to the viewmodel:

C#
public CartData SelectedCartData


and bind the Selected property of the listview in XAML making sure to set the Mode to TwoWay. This way the binding is pulling data from the cartData collection and pushing the selected value back into the viewmodel. Once this happens, you can then call:

cartData.Remove(SelectedCartData);
 
Share this answer
 

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