|
using System.ComponentModel;
using System.Windows;
namespace TaskList.ViewModel
{
public abstract class TaskListViewModel : INotifyPropertyChanged
{
ITaskListApplication application;
protected TaskListViewModel()
{
application = Application.Current as ITaskListApplication;
if (application != null)
application.PropertyChanged += application_PropertyChanged;
}
void application_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == "Tasks")
OnPropertyChanged("Tasks");
}
public ITaskListApplication TaskListApplication
{
get
{
return application;
}
set
{
if (application != value)
{
SetApplication(value);
OnPropertyChanged("TaskListApplication");
}
}
}
protected virtual void SetApplication(ITaskListApplication value)
{
if (application != null)
application.PropertyChanged -= application_PropertyChanged;
application = value;
if (application != null)
application.PropertyChanged += application_PropertyChanged;
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, e);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Windows developer with 10+ years experience working in the banking industry.