Esempio n. 1
0
        // this is the callback that is called when a bound value in an IPropertyWatcher is changed
        private void handleChange(string propertyName, IPropertyWatcher instance)
        {
            List <AbstractDataBinding> bindingList;
            string propertyReference = makePropertyReference(instance.GUID, propertyName);

            if (_bindings.TryGetValue(propertyReference, out bindingList))
            {
                // we're now handling this change, add it to the stack
                _changesBeingHandled.Push(propertyReference);

                foreach (var binding in bindingList)
                {
                    if (_changesBeingHandled.Contains(binding.TargetReference))
                    {
                        // the Target of this change is one that we've already handled,
                        // so it will be no use setting it again
                        continue;
                    }

                    binding.Invoke();
                }

                // we've finished handling this change
                _changesBeingHandled.Pop();
            }
        }
Esempio n. 2
0
        public void Bind <TType>(Expression <Func <TType> > binder, Expression <Func <TType> > bindee, BindingType bindingType)
        {
            var binderMemberExp              = (MemberExpression)binder.Body;
            IPropertyWatcher binderInstance  = Expression.Lambda <Func <IPropertyWatcher> >(binderMemberExp.Expression).Compile()();
            string           binderReference = makePropertyReference(binderInstance.GUID, binderMemberExp.Member.Name);

            var bindeeMemberExp              = (MemberExpression)bindee.Body;
            IPropertyWatcher bindeeInstance  = Expression.Lambda <Func <IPropertyWatcher> >(bindeeMemberExp.Expression).Compile()();
            string           bindeeReference = makePropertyReference(bindeeInstance.GUID, bindeeMemberExp.Member.Name);

            DataBinding <TType> binding = new DataBinding <TType>(binder, bindee, bindeeReference);

            createBinding(binderReference, binding);

            if (bindingType == BindingType.TwoWay)
            {
                DataBinding <TType> oppositeBinding = new DataBinding <TType>(bindee, binder, binderReference);
                createBinding(bindeeReference, oppositeBinding);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Deregister a data class with this BindBroker. This is the inverse of <c>RegisterData()</c>.
 /// </summary>
 /// <param name="watcher">Instance of the class (implementing IPropertyWatcher) to unbind.</param>
 public void DeregisterData(IPropertyWatcher watcher)
 {
     watcher.OnPropertyChange -= handleChange;
 }