Reputation: 12294
i am making a book app. i have got the new releases
list and the favorites
list in the panorama. Now beside every record in the new releases
list there is an add to favorite
button which add that particular book to the favorite
list when clicked and then that particular add to favourite
button is removed.`
my favorite
list has got the remove button beside every record.
problem.
now when clicking remove me button(of the any particular record) in the favourite
list what is the recommended strategy to again show the add to favourite
button in the newreleases list which was removed ,real time.
one way is loading the list again which i don't think will be the right move as it is the very first page of the app.
Upvotes: 0
Views: 279
Reputation: 464
With each item in the new releases
and favorites
list, assign a unique id.So each item has a unique id while loading on the lists, be it new releases
or favorites
.
When you tap on add to favorites
,all goes good as you say.
Now when you tap on remove from favorites
, retrieve the unique id of that ListItem
using Listbox.SelectedItem
property ( I am considering your ObservableCollection
to be a collection of the class Book.cs
private void favoritesListTap(object sender, System.Windows.Input.GestureEventArgs e)
{
Book data = (sender as ListBox).SelectedItem as Book;
int selectedid = data.unique_id;
//Now find that item in the `new releases` list which has the same unique_id as the one we just retrived
foreach( Book bk in newleases.Items)
{
if( bk.unique_id == selectedid)
{
bk.SetFavoriteIcon = "addtofav.png";
break;
}
}
}
use SetFavoriteIcon in Book.cs to set your icon and style with INotifyPropertyChanged
event. This will change that one particular list item you want to have the add to favorite
button back.
Upvotes: 1
Reputation: 2568
Use the same ItemViewModel for the items in for both lists. Add an IsFavorite bool notifiable property on it and toggle it when an Item gets favorited or un-favorited. Then in the new releases list show the AddToFavorites button only when IsFavorite is false and do the opposite for the favorites list. Also add two Commands in the ItemViewModel named AddToFavoritesCommand and RemoveFromFavoritesCommand that will remove/add the current item from the newreleases/favorites list and toggle the IsFavorite flag respectively.
Upvotes: 0