Skip to content
Advertisement

Saving with SQL

Hi all I have a page that I’m trying to ADD to a list and save it with viewmodel and SQL. but my list is empty Can you tell me where am I wrong??

on my Xaml (Page1):

my Model (Energypage):

And on my EnergyViewModel:

I did bond my page1 to Energyviewmodel, and it works find when I didn’t use SQL service, I think my SQL has problem…

I have debug the viewmodel and program run to the end of the Viewmodel but my xaml page list is empty.

Advertisement

Answer

this line creates a completely new instance of energyX when your ListView is bound to the old instance

energyX = new ObservableCollection(conn.Table().ToList());

there are two ways you could fix this

option 1, use INotifyPropertyChanged and raise a PropertyChanged event in the setter of energyX

option 2, don’t create a new instance of energyX. Instead just add the new item to the existing instance

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement