My Sqlite inset, but whe I read it there is none

Eduardo Gomez 3,671 Reputation points
2021-03-16T18:07:38.497+00:00
public class Contact : ViewModelBase {

    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    private string _Name;
    public string Name {
        get { return _Name; }
        set {
            if (_Name != value) {
                _Name = value;
                RaisePropertyChanged();
            }
        }
    }

    private string _PhoneNumber;
    public string PhoneNumber {
        get { return _PhoneNumber; }
        set {
            if (_PhoneNumber != value) {
                _PhoneNumber = value;
                RaisePropertyChanged();
            }
        }
    }

    private string _Address;
    public string Address {
        get { return _Address; }
        set {
            if (_Address != value) {
                _Address = value;
                RaisePropertyChanged();
            }
        }
    }
}

}

using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace ContactXam.ViewModel {
public class ViewModelBase : INotifyPropertyChanged {

    #region Notify Property Changed Members
    public event PropertyChangedEventHandler PropertyChanged;
    protected void RaisePropertyChanged([CallerMemberName] string propertyName = "") {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    #endregion
}

}

Developer technologies | .NET | Xamarin
SQL Server | Other
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-03-18T03:04:46.587+00:00

    when I save a contact and come POP the page, I don't see my new contact, I have to restart the app to see

    To update the UI at runtime, please make sure the model class inherits from the INotifyPropertyChanged interface or the BindableObject class to raise the PropertyChanged event such as:

       public class TestModel : INotifyPropertyChanged  
       {  
           private string content;  
           public string Content  
           {  
               get  
               {  
                   return content;  
               }  
               set  
               {  
                   if (content != value)  
                   {  
                       content = value;  
                       NotifyPropertyChanged("Content");  
                   }  
               }  
           }  
         
           protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")  
           {  
               PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));  
           }  
           public event PropertyChangedEventHandler PropertyChanged;  
       }  
    

    Check the doc: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/xaml/xaml-basics/data-bindings-to-mvvm


1 additional answer

Sort by: Most helpful
  1. StephenH 86 Reputation points
    2021-03-17T00:02:52.653+00:00

    Here is a simple example of my code to insert 1 or many of something

    78505-image.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.