예제 #1
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public ObservedCollection(object obj, LayoutRoot layoutRoot)
        {
            Type objType = obj.GetType();

            if (objType.IsGenericType)
            {
                if (objType.GetGenericTypeDefinition() == typeof(ObservableCollection <>))
                {
                    // if object is of type ObservableCollection<> we subscribe to INotifyCollectionChanged events
                    _genericList      = obj as IList;
                    _hasBindableItems = BindableObjectType.IsAssignableFrom(objType.GetGenericArguments()[0]);

                    // get event to register to it
                    var eventInfo = objType.GetEvent("CollectionChanged");
                    var handler   = Delegate.CreateDelegate(eventInfo.EventHandlerType, this, nameof(OnCollectionChanged));
                    eventInfo.AddEventHandler(obj, handler);
                }
                else if (objType.GetGenericTypeDefinition() == typeof(List <>))
                {
                    // if object is of type List<> we track changes each frame
                    _genericList      = obj as IList;
                    _hasBindableItems = BindableObjectType.IsAssignableFrom(objType.GetGenericArguments()[0]);
                    layoutRoot.RegisterUpdateable(this);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Adds change listener to object.
 /// </summary>
 private void AddChangeListener(BindingPath source, object sourceObject)
 {
     if (BindableObjectType.IsAssignableFrom(sourceObject.GetType()))
     {
         var bindableSourceObject = sourceObject as BindableObject;
         bindableSourceObject.PropertyChanged += source.PropertyChanged;
     }
     else
     {
         if (!HasRegisteredInLayoutRoot)
         {
             LayoutRoot.RegisterUpdateable(this);
             HasRegisteredInLayoutRoot = true;
         }
     }
 }