why RaisePropertyChange is not working inside
public partial class MainWindow : Window
{
private string _searchString;
public string SearchString
{
get { return _searchString; }
set
{
_searchString = value;
RaisePropertyChanged(() => SearchPersonEHistroy);
}
}
}
It gives error “RaisePropertyChanged’ does not exist in the current context”
but when i tried to use like this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainViewModel();
}
public class MainViewModel : NotificationObject
{
private string _searchString;
public string SearchString
{
get { return _searchString; }
set
{
_searchString = value;
RaisePropertyChanged(() => SearchPersonEHistroy);
}
}
}
}
what’s the difference between them? or do we have any convertion for RaisePropertyChange inside public partial class MainWindow : Window?
RaisePropertyChanged()is defined by theNotificationObjectclass, notWindow.Since
Windowis already aDependencyObjectyou should make itsSearchStringproperty a dependency property which will allow you to bind it with theSearchStringproperty of the View Model.