KentZhou
KentZhou

Reputation: 25573

How to raise property changed event from outside of Entity?

Entities already implement the PropertyChanged. If properties are changed, PropertyChanged will be fired.
What I want now is: I want to fire PropertyChanged event in code even the value actually not changed (for binding purpose). I want to do something like from outside of the entity:

MyEntity.RaisedPropertyChanged("myProperty");

Also know that Entities have OnPropertyChanged method, but it is protected, only available inside the class or its subclass.

How to implement this request?

Upvotes: 0

Views: 2432

Answers (2)

Aaron Anodide
Aaron Anodide

Reputation: 17196

Someone else might point out a why you shouldn't have to do this, but one simple thing is to add a public method that relays to the protected method.

public partial class MyEntity
{    
    public void RaisePropertyChanged(string propertyName)
    {
       this.RaisedPropertyChanged(propertyName);
    }
}

Upvotes: 1

Khan
Khan

Reputation: 18162

You can create a public method inside a partial class for MyEntity that fires calls the protected method.

Upvotes: 0

Related Questions