binding - WPF: static INotifyPropertyChanged event -


this model:

class person : inotifypropertychanged {     public static int counter;     public string _firstname;     public string _lastname;     public event propertychangedeventhandler propertychanged;     public string firstname    {         {return _firstname; }         set         {             _filename = value;             notifypropertychange("firstname");                         }    }     public addperson(person person)    {        counter++;    } } 

i have notifypropertychange changed persons properties inside listview , want add counter field hold number of objects have. possible add propertychanged event static variable ?

instead of static counter should have view model collection of person objects

public class viewmodel {     public observablecollection<person> persons { get; set; } } 

and bind itemssource property of listview collection.

<listview itemssource="{binding persons}">     ... </listview> 

you bind count property of collection number of elements:

<textblock text="{binding persons.count}"/> 

for further reading see binding collections section in data binding overview article on msdn.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -