This is a migrated thread and some comments may be shown as answers.

Update one item after an CellSwipe

3 Answers 59 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 09 Feb 2018, 05:02 PM

Hi, I got a CellSwipe that change the status of one item.

Ex: Item1.Status = "toto";

So when Item is swaped, I change the status, save it in my offline local DB then do a OnlineSync for Azure. The item is correctly changed in BD (local and server), but how do I update the item in the listview without reloading from local DB and update the collection himself?

3 Answers, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 09 Feb 2018, 08:11 PM
Hi Pierre,

In order to see changes reflected in the UI after initial binding you'll need to make sure that property has PropertyChanged wired up. 

Using your example of Status property, here's what that would look like:

public class ItemModel : INotifyPropertyChanged
{
    private string status;
 
    public string Status
    {
        get { return status; }
        set
        {
            if (value == status) return;
            status = value;
 
            // This is required
            OnPropertyChanged();
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}



Demo

You can see this in action with our Cell Swipe documentation's example here.

Notice how the IsUnread property of the Mail model calls OnPropertyChanged?

public class Mail : NotifyPropertyChangedBase
{
    bool isUnread;
 
    public string Sender { get; set; }
 
    public string Subject { get; set; }
 
    public bool IsUnread
    {
        get { return isUnread; }
        set
        {
            if (this.isUnread != value)
            {
                isUnread = value;
                OnPropertyChanged();
            }
        }
    }
}

If you swipe the item to the right more than 70 pixels, the IsUnread value changes (and the item in the list is updated because of property changed notificaiton).

void OnItemSwipeCompleted(object sender, ItemSwipeCompletedEventArgs e)
{
    var listView = sender as RadListView;
    var item = e.Item as Mail;
 
    listView.EndItemSwipe();
 
    if (e.Offset >= 70)
    {
        item.IsUnread = false;
    }
    else if (e.Offset <= -70)
    {
        (listView.ItemsSource as ObservableCollection<Mail>).Remove(item);
    }
}


If you continue to have trouble with this, please open a support ticket here and attach your code so that I can investigate directly.

Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pierre
Top achievements
Rank 1
answered on 09 Feb 2018, 08:42 PM
Thanks that work. I was not sure if I can add this kind of property and add PropertyChange when my class is used in Azure Client too. But it seems to work without issue.
0
Lance | Manager Technical Support
Telerik team
answered on 10 Feb 2018, 12:21 AM
Hello Pierre,

Yep! You can safely add metadata (i.e. RadDataForm annotations) and property changed logic to a class that you're using for your IMobileServiceSyncTable<YourModel>. As long as you don't change the names of the properties, the MobileServiceClient will serialize it and the API's Controller will be able to match the model.

Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ListView
Asked by
Pierre
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Pierre
Top achievements
Rank 1
Share this question
or