예제 #1
0
 public void Dispose()
 {
     Unapply();
     m_Target          = null;
     m_Source          = null;
     context           = null;
     bindingExpression = null;
 }
예제 #2
0
        public BindingNode(IBindingExpression bindingExpression, Type resultType, ITupleSource source)
        {
            BindingExpression = bindingExpression;
            ResultType        = resultType;
            Source            = source;

            Source.Attach(this);
        }
예제 #3
0
        public static IBindingExpression SetBinding(IBindable target, string targetProperty, Binding binding)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (string.IsNullOrEmpty(targetProperty))
            {
                throw new ArgumentNullException("targetProperty");
            }


            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            var binderKey = _Bindings.SingleOrDefault((kvp) => kvp.Key.Object == target && kvp.Key.Property == targetProperty).Key;

            IBindingExpression bindingExpression = null;

            object nestedTarget = target;
            var    element      = target as Element;

            PropertyInfo propertyInfo = target.GetType().GetNestedProperty(ref nestedTarget, targetProperty, false);
            var          targetReady  = propertyInfo != null && nestedTarget != null;

            if (targetReady)
            {
                if (_BindingExpressions == null)
                {
                    _BindingExpressions = new List <IBindingExpression>();
                }

                bindingExpression = GetBindingExpression(target, targetProperty);

                if (bindingExpression == null)
                {
                    bindingExpression = new BindingExpression(binding, propertyInfo, nestedTarget)
                    {
                        Element = element
                    };

                    _BindingExpressions.Add(bindingExpression);

                    var INPC = bindingExpression.Binding.Source as INotifyPropertyChanged;
                    if (INPC != null)
                    {
                        INPC.PropertyChanged -= HandleDataContextPropertyChanged;
                        INPC.PropertyChanged += HandleDataContextPropertyChanged;
                    }
                }
            }
            else
            {
                if (binderKey == null)
                {
                    _Bindings.Add(new PropertyBinder()
                    {
                        Object = target, Property = targetProperty
                    }, binding);
                }
                else
                {
                    _Bindings[binderKey] = binding;
                }
            }

            return(bindingExpression);
        }
		public static void SetNotificationCollectionHandler(IBindingExpression bindingExpression, INotifyCollectionChanged collection)
		{
			NotifyCollectionChangedEventHandler handler = (sender, e) => 
			{
				var section = bindingExpression.Element as ISection;
				section.CollectionChanged(e);

//				bindingExpression.UpdateTarget();
			};			

			collection.CollectionChanged -= handler;
			collection.CollectionChanged += handler;
		}
예제 #5
0
        public static IBindingExpression SetBinding(IBindable target, string targetProperty, Binding binding)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (string.IsNullOrEmpty(targetProperty))
            {
                throw new ArgumentNullException("targetProperty");
            }


            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            var binderKey = _Bindings.SingleOrDefault((kvp) => kvp.Key.Object == target && kvp.Key.Property == targetProperty).Key;

            IBindingExpression bindingExpression = null;

            object nestedTarget = target;
            var    element      = target as IElement;

            var        name       = string.Concat(targetProperty, "Property.Value");
            MemberInfo memberInfo = target.GetType().GetNestedMember(ref nestedTarget, name, false);

            if (memberInfo != null)
            {
                binding.TargetPath = name;
                binding.Target     = nestedTarget;
            }
            else
            {
                nestedTarget = target;
                memberInfo   = target.GetType().GetNestedMember(ref nestedTarget, targetProperty, false);
            }

            var targetReady = memberInfo != null && nestedTarget != null;

            if (targetReady)
            {
                if (_BindingExpressions == null)
                {
                    _BindingExpressions = new List <IBindingExpression>();
                }

                bindingExpression = GetBindingExpression(target, targetProperty);

                if (bindingExpression == null)
                {
                    bindingExpression = new BindingExpression(binding, memberInfo, nestedTarget)
                    {
                        Element = element
                    };

                    _BindingExpressions.Add(bindingExpression);

                    var vmINPC = bindingExpression.Binding.Source as INotifyPropertyChanged;
                    if (vmINPC != null)
                    {
                        vmINPC.PropertyChanged -= HandleDataContextPropertyChanged;
                        vmINPC.PropertyChanged += HandleDataContextPropertyChanged;
                    }

                    var viewINPC = bindingExpression.Binding.ViewSource as INotifyPropertyChanged;
                    if (viewINPC != null)
                    {
                        viewINPC.PropertyChanged -= HandleDataContextPropertyChanged;
                        viewINPC.PropertyChanged += HandleDataContextPropertyChanged;
                    }
                }
            }
            else
            {
                if (binderKey == null)
                {
                    _Bindings.Add(new PropertyBinder()
                    {
                        Object = target, Property = targetProperty
                    }, binding);
                }
                else
                {
                    _Bindings[binderKey] = binding;
                }
            }

            return(bindingExpression);
        }
예제 #6
0
 public BindingNode(IBindingExpression bindingExpression)
 {
     BindingExpression = bindingExpression;
 }
예제 #7
0
        public static IBindingExpression SetBinding(IBindable target, Binding binding)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            var targetProperty = binding.TargetPath;

            IBindingExpression bindingExpression = null;

            object dataBinding  = target.DataBinding;
            object nestedTarget = dataBinding;
            var    element      = target as IElement;

            MemberInfo memberInfo           = null;
            FieldInfo  bindablePropertyInfo = null;

            if (dataBinding != null)
            {
                var name = string.Concat(targetProperty, "Property");
                bindablePropertyInfo = dataBinding.GetType().GetField(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.FlattenHierarchy);

                name       = string.Concat(name, ".ControlValue");
                memberInfo = dataBinding.GetType().GetNestedMember(ref nestedTarget, name, false);
                if (memberInfo != null)
                {
                    binding.TargetPath = name;
                    binding.Target     = nestedTarget;
                }
            }

            var targetReady = memberInfo != null && nestedTarget != null && binding.Source != null;

            if (targetReady)
            {
                if (_BindingExpressions == null)
                {
                    _BindingExpressions = new List <IBindingExpression>();
                }

                bindingExpression = GetBindingExpression(binding);

                if (bindingExpression != null)
                {
                    _BindingExpressions.Remove(bindingExpression);
                }

                bindingExpression = new BindingExpression(binding, memberInfo, nestedTarget)
                {
                    Element = element
                };

                _BindingExpressions.Add(bindingExpression);

                var vmINPC = bindingExpression.Binding.Source as INotifyPropertyChanged;
                if (vmINPC != null)
                {
                    vmINPC.PropertyChanged -= HandleDataContextPropertyChanged;
                    vmINPC.PropertyChanged += HandleDataContextPropertyChanged;
                }

                var viewINPC = bindingExpression.Binding.ViewSource as INotifyPropertyChanged;
                if (viewINPC != null)
                {
                    viewINPC.PropertyChanged -= HandleDataContextPropertyChanged;
                    viewINPC.PropertyChanged += HandleDataContextPropertyChanged;
                }

                var sourceValue = bindingExpression.GetSourceValue();

                var sourceCollection = sourceValue as INotifyCollectionChanged;
                if (sourceCollection != null)
                {
                    throw new NotImplementedException("TODO: implement collections for binding in BindingOperations.cs");
                    //SetNotificationCollectionHandler(bindingExpression, sourceCollection);
                }
            }
            else
            {
                var binderKey = _Bindings.SingleOrDefault((kvp) => kvp.Key.Object == target && kvp.Key.Property == targetProperty).Key;

                if (binderKey == null)
                {
                    _Bindings.Add(new PropertyBinder()
                    {
                        Object = target, Property = targetProperty
                    }, binding);
                }
                else
                {
                    _Bindings[binderKey] = binding;
                }
            }

            if (bindablePropertyInfo != null)
            {
                var bindableProperty = bindablePropertyInfo.GetValue(dataBinding) as BindableProperty;
                if (bindableProperty != null)
                {
                    bindableProperty.BindingExpression = bindingExpression;
                }
            }

            return(bindingExpression);
        }
예제 #8
0
        public override void SetUp()
        {
            base.SetUp();

            this.Expression = this.GetExpression();
        }
예제 #9
0
 public void Initialize()
 {
     bindingExpression = BindingUtility.NewExpression(this);
     isInitialize      = true;
 }