Say I have an entity with also non-persistent properties. DO4 implements INotifyPropertyChanged, and raises PropertyChanged event for persistent fields. I also would like to raise PropertyChanged event for my non-persistent fields. What is the best way to do this? I cannot raise the event because it's not in my class. A protected method for raising PropertyChanged would be helpful.


Updated at 01.06.2010 11:21:28

Solved. This way:

    protected void RaisePropertyChanged(string propertyName)
    {
        var subscription = base.GetSubscription(EntityEventBroker.PropertyChangedEventKey);
        if(subscription.Second != null)
            ((PropertyChangedEventHandler)subscription.Second)
              .Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by otto.

asked May 31 '10 at 19:34

Editor's gravatar image

Editor
46152156157


One Answer:

You must use NotifyPropertyChanged(string propertyName) or NotifyFieldChanged(FieldInfo field). The second method actually calls the first one:

protected internal void NotifyFieldChanged(FieldInfo field)
{
  if (!Session.EntityEvents.HasSubscribers)
    return;

  var rootField = field;
  while (rootField.Parent != null)
    rootField = rootField.Parent;

  NotifyPropertyChanged(rootField.Name);
}

So it raises the event for topmost structure field, if the field is nested (i.e. declared inside Structure type).

Both methods are protected.

answered Sep 29 '10 at 08:31

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA