/// <summary>
        /// Subscribes supplied object to property changed notifications and invokes the provided callback
        /// </summary>
        /// <typeparam name="T">Type of subject</typeparam>
        /// <param name="vmb">Subject</param>
        /// <param name="path">Property path</param>
        /// <param name="callback">Notification callback</param>
        public static void NotifyOn <T>(this T vmb, string path, Action <object, object> callback)
        {
            Dictionary <string, NotificationHelperDp> block;

            if (!_notifiers.TryGetValue(vmb, out block))
            {
                _notifiers.Add(vmb, block = new Dictionary <string, NotificationHelperDp>());
            }
            block.Remove(path);

            NotificationHelperDp binder = new NotificationHelperDp(callback);

            BindingOperations.SetBinding(binder, NotificationHelperDp.BindValueProperty,
#if NET || NETCORE || NETFRAMEWORK
                                         new Binding(path)
            {
                Source = vmb
            });
#else
                                         new Binding {
                Source = vmb, Path = new PropertyPath(path)
            });
#endif
            block.Add(path, binder);
        }
Example #2
0
        private static void OnBindValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            NotificationHelperDp that = (NotificationHelperDp)d;

            if (!that._isDetached && that._callback != null
#if NET || NETCORE || NETFRAMEWORK
                && BindingOperations.IsDataBound(that, BindValueProperty)
#endif
                )
            {
                that._callback(e.NewValue, e.OldValue);
            }
        }