Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Implementing INotifyPropertyChanged in xamarin.forms

$
0
0

Hi everyone, so I have a model class and I want to creat a ViewModel so that I can track the changes that happen in one of my Model class arguments.
what should I do ?
this what I've done so far
Model Class :

public class Objets
    {
    public string Designation { get; set; }
    public string Description { get; set; }
    public float Prix { get; set; }
    public int nbr_objet { get; set; }
    public Objets(string Designation, string Description, float Prix, int nbr_objet)
    {
        this.Designation = Designation;
        this.Description = Description;
        this.Prix = Prix;
        this.nbr_objet= nbr_objet;
    }
    }

ModelViewBase where I have the problem obviously

class ViewModelBase : INotifyPropertyChanged
    {
    public Objets ObjetVM { get; set; }
    public int nbr_objet 
    {
        get { return ObjetVM.nbr_objet; }
        set
        {
            ObjetVM.nbr_objet = value;
            OnPropertyChanged(nameof(ObjetVM.nbr_objet));
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;

    public void OnPropertyChanged(string propertyname)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
    }
}

And this is my .XAML.CS page

    public MenuPage()
    {
        InitializeComponent();
        this.BindingContext = new ViewModelBase();
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>