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
0
Accepted
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:
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?
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).
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
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 2
Iron
Iron
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
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
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