Reputation: 38114
It is really weird, but UI is not updated when I call BindableBase.SetProperty()
:
private string person;
public string Person
{
get { return person; }
set
{
person = value;
SetProperty(ref this.person, value);//Not updating UI
//OnPropertyChanged("Person");//It works really nice
}
}
I am using Prism.Core.6.1.0\lib\net45\Prism.dll
and its Version=6.1.0.0
.
However, OnPropertyChanged(string propertyName)
perfectly works:
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
What I am missing? Any help would be greatly appreciated!:)
Upvotes: 1
Views: 2428
Reputation: 26213
The way SetProperty
works is by doing all the required update logic for you. It will check if the value has changed, then either return immediately or update the value (which it can do, as it's passed by ref
) and then raise the property changed event.
You're doing half its job in advance, so it will always return immediately as it will find no difference between the person
field and value
.
Just change your property to:
public string Person
{
get { return person; }
set { SetProperty(ref person, value); }
}
Upvotes: 4
Reputation: 10349
That's because of the person = value;
instruction. BindableBase.SetProperty
checks for equality between the two parameters, and only raises the PropertyChanged
event if they're not equal. So removing this line should help.
Upvotes: 4