I am very new to programming. Trying to understand the basic idea of MVVM using this tutorial http://social.technet.microsoft.com/wiki/contents/articles/13536.easy-mvvm-examples-in-extreme-detail.aspx
I removed the interface " : INotifypropertychanged" from this code (Deleted those words). Still this program runs and behaves as intended. Then what is he purpose of INotifyPropertychanged here?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;
using System.Windows.Threading;
namespace MvvmExample.ViewModel
{
class ViewModelBase : INotifyPropertyChanged
{
//basic ViewModelBase
internal void RaisePropertyChanged(string prop)
{
if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(prop)); }
}
public event PropertyChangedEventHandler PropertyChanged;
//Extra Stuff, shows why a base ViewModel is useful
bool? _CloseWindowFlag;
public bool? CloseWindowFlag
{
get { return _CloseWindowFlag; }
set
{
_CloseWindowFlag = value;
RaisePropertyChanged("CloseWindowFlag");
}
}
public virtual void CloseWindow(bool? result = true)
{
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
CloseWindowFlag = CloseWindowFlag == null
? true
: !CloseWindowFlag;
}));
}
}
}