eliteKit
Xamarin UI Kit
Welcome back

How to clear bound eliteNumberCounter

Created by Phil Seeman • 2020-06-23 09:31 PM

Phil Seeman
PRO User
3
Posts
0
Likes
0 likes

I have a ListView bound to an ObservableCollection of objects. The ListView's ItemTemplate contains an eliteNumberCounter which is bound to an integer property of the bound object.

 

My goal is to clear all items in the ListView from my ViewModel; that is, have all eliteNumberCounters set to 0. I'm looping through each item in the ObservableCollection and setting the integer property to 0. I was hoping that by doing that, all of the eliteNumberCounters would set themselves to 0 (since they are bound). But there is no change in any eliteNumberCounter when I do this clear operation.

 

How can I accomplish what I'm wanting? Thanks.

 

Created 2020-06-23 09:31 PM
Ricardo Vasquez
Administrator
30
Posts
10
Likes
1 likes

Hello Phil,

 

My suggestion is you to double check that your binded Model is implementing correctly INotifyPropertyChanged as described in this thread since this is a common issue. Also make sure you are using a recent version of Xamarin.Forms.

 

If this is not working you can trigger the change manually by using a call similar to this one in your view model:

 

YourObservableCollection = new ObservableCollection<YourTable>(list with modified entries); in order to see your changes are being updated correctly.Hope it helps!

Created 2020-06-24 07:23 AM
Phil Seeman
PRO User
3
Posts
0
Likes
0 likes

Hi Ricardo,

 

Thanks for the reply! I'm not sure why the model is not updating automatically but your manual-trigger suggestion of re-instantiating the Observable Collection worked perfectly.

Created 2020-06-24 06:49 PM
Ricardo Vasquez
Administrator
30
Posts
10
Likes
0 likes

Glad it worked for you. Please double check you are correctly implementing INotifyPropertyChanged in your ViewModel and your Models. It is good practice to have a BaseViewModel and a BaseModel in which is implemented.

 

Cheers!

Created 2020-06-25 08:05 AM
We are using cookies!
This website uses cookies to ensure you get the best experience on our website. We're sorry that you can't eat them.
eliteKit
Create beautiful Xamarin Forms apps with eliteKit.
A collection of a lot UI elements made in SkiaSharp.
0
community members
0
eliteKit PRO members
0
eliteKit LITE downloads
0
eliteKit elements
Copyright © 2020. All rights reserved. Made with a lot of love and caffeine.
Powered by eliteCode.