Reputation: 135
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?
Upvotes: 0
Views: 3986
Reputation: 887837
RaisePropertyChanged()
is defined by the NotificationObject
class, not Window
.
Since Window
is already a DependencyObject
you should make its SearchString
property a dependency property which will allow you to bind it with the SearchString
property of the View Model.
Upvotes: 2