private void OnChildPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) { var subscription = NotifySubscribers.FirstOrDefault(pair => pair.Value.Equals(sender)); var args = new NotifyRouter.ChildPropertyChangedEventArgs(propertyChangedEventArgs.PropertyName) { ParentPropertyName = subscription.Key, Value = sender.GetType().GetProperty(propertyChangedEventArgs.PropertyName).GetValue(sender) }; ChildPropertyChanged?.Invoke(sender, args); }
private void SetNotifyRouting <T>(ref T oldValue, T newValue, string propertyName) { if (oldValue is INotifyPropertyChanged notifyOldValue) { if (NotifySubscribers.ContainsKey(propertyName)) { NotifySubscribers[propertyName].PropertyChanged -= OnChildPropertyChanged; } } SubscribeChildNotifications(newValue, propertyName); }
private void SubscribeChildNotifications <T>(T newValue, string propertyName) { if (newValue is INotifyPropertyChanged notifyNewValue) { if (!NotifySubscribers.ContainsKey(propertyName)) { NotifySubscribers.Add(propertyName, notifyNewValue); } notifyNewValue.PropertyChanged += OnChildPropertyChanged; } }
//call the event public void Notify(string name) { list.Add(name); //instantiate the delegate NotifySubscribers ns = new NotifySubscribers((l) => { Console.WriteLine("Welcome {0}", name); }); //bind the delegate to the event EventNotify += ns; }
public void UnSubscribeForVideo(NotifySubscribers subscriber) { NotifySubsribersHandler -= subscriber; }