public class MainPageViewModel : ViewModelBase
{
private ObservableCollection<Company> _Companies;
private Company _CurrentCompany;
/* ... */
public ObservableCollection<Company> CompanyList
{
get
{
return _Companies;
}
set
{
if (_Companies != value)
{
_Companies = value;
OnPropertyChanged("CompanyList");
}
}
}
public Company CurrentCompany
{
get
{
return _CurrentCompany;
}
set
{
if (_CurrentCompany != value)
{
_CurrentCompany = value;
OnPropertyChanged("CurrentCompany");
}
}
}
}
public abstract class ViewModelBase : INotifyPropertyChanged
{
public bool IsDesignTime
{
get { return DesignerProperties.IsInDesignTool; }
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propName)
{
var propChanged = PropertyChanged;
if (propChanged != null)
{
propChanged(this, new PropertyChangedEventArgs(propName));
}
}
}
public class Company : INotifyPropertyChanged
{
public string Name { get; set; }
public string Value { get; set; }
public Company(string name, string value)
{
Name = name;
Value = value;
}
protected virtual void OnPropertyChanged(String propertyName)
{
if (_propertyChanged != null)
{
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
protected virtual void OnNavigationPropertyChanged(String propertyName)
{
if (_propertyChanged != null)
{
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
private event PropertyChangedEventHandler _propertyChanged;
private ObjectChangeTracker _changeTracker;
}