简体   繁体   中英

Deal with data as DataTable to Observable Collection in xamarin forms

I would like to take advice from your side. As you know mostly in xamarin forms enter code here using mvvm pattern in the view models , people used to use most of the time ObservableCollection to hold items. I have old windows forms application and some class libraries when i have methods which get data as DataTable . I already migrated all class libraries from .NET framework to .Net Standard to be able to share logic also in Xamarin , nevertheless i wonder how i can deal when getting data for instance DataTable GetAllPeple() . Should i just somehow convert DataTable placed in my repository class data to ObseravbleCollection placed in ViewModel? Can anyone give me a hint how this could be done. Also vice versa when want to update some records. Hope you got my point. Thanks to all of you.

If you follow the MVVM or similar pattern, you should handle the GetAllPeople data in the ViewModel only, and put it into the Model (to the ObservableCollection) along with other model data the View needs. If you can access the DataTable as a collection and get rows and columns, create a class with needed properties (and INotifyPropertyChanged) turn the rows and columns into properties in the class and add to the ObservableCollection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM