Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mobile.Mvvm.DataBinding.BindingExpression"/> class.
        /// </summary>
        public BindingExpression(object target, string targetProperty, object source, Binding binding)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

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

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

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

            this.PropertyAccessor = new ReflectionPropertyAccessor(targetProperty);
            this.Initialize(target, targetProperty, source, binding);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Mobile.Mvvm.DataBinding.WeakBindingExpression"/> class.
        /// </summary>
        public WeakBindingExpression(object target, string targetProperty, IPropertyAccessor accessor, object source, Binding binding)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            
            if (string.IsNullOrEmpty(targetProperty))
            {
                throw new ArgumentNullException("targetProperty");
            }
            
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }

            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
            
            this.SafelyUpdateTarget = true;
            this.PropertyAccessor = accessor;
            this.Initialize(target, targetProperty, source, binding);
        }
        /// <summary>
        /// Sets the binding between target and source.
        /// </summary>
        public static IBindingExpression AddBinding(this IPropertyInjection target, string propertyName, object source, Binding binding)
        {
            var scope = target.GetBindingScopeOrDefault();

            var expression = new WeakBindingExpression(target, propertyName, source, binding);
            scope.Add(expression);
            return expression;
        }
        public void WhenDisposingTheExpression_ThenTargetObjectEventIsNull()
        {
            this.SetUp();
            var binding = new Binding("Property1");
            var expression = new EventTriggeredBindingExpression<EventTargetObject, EventArgs>(this.Target, "PropertyA", "PropertyChanged", this.Source, binding);
            expression.Bind();

            expression.Dispose();

            Assert.AreEqual(this.Target.HasEventHandler, false);
        }
        public void WhenBindingWithAnEvent_ThenTheSourcePropertyIsUpdated()
        {
            this.SetUp();
            var binding = new Binding("Property1");
            var expression = new EventTriggeredBindingExpression<EventTargetObject, EventArgs>(this.Target, "PropertyA", "PropertyChanged", this.Source, binding);
            expression.Bind();

            this.Target.PropertyA = Guid.NewGuid().ToString();

            Assert.AreEqual(this.Target.PropertyA, this.Source.Property1);
        }
Esempio n. 6
0
        private IBindingExpression ParseSingleExpression(string expression, object target, object source)
        {
            var tokens = this.Tokenise(expression);
            if (tokens.Count != 3 && tokens.Count != 5)
            {
                return null;
            }

            var targetProperty = tokens[0];
            var bindingMode = this.ModeFromToken(tokens[1]);

            var sourceProperty = string.Empty;
            IValueConverter converter = null;
            object convertParam = null;
            
            if (tokens.Count == 3)
            {
                sourceProperty = tokens[2].Trim();
            }
            else
            {
                converter = ConverterFromToken(tokens[2]);
                sourceProperty = tokens[3];
                convertParam = tokens[4];
            }

            var binding = new Binding(sourceProperty);
            binding.Converter = converter;
            binding.ConverterParameter = convertParam;
            binding.Mode = bindingMode;

            return new WeakBindingExpression(target, targetProperty, source, binding);
        }
 /// <summary>
 /// Sets the binding between target and source.
 /// </summary>
 public static IBindingExpression AddBinding(this IBindingScope scope, object target, string propertyName, object source, Binding binding)
 {
     var expression = new WeakBindingExpression(target, propertyName, source, binding);
     scope.Add(expression);
     return expression;
 }
 /// <summary>
 /// Sets the binding between target and source.
 /// </summary>
 public static IBindingExpression AddBinding(this IBindingScope scope, object target, object source, Binding binding)
 {
     return scope.AddBinding(target, binding.PropertyName, source, binding);
 }
        /// <summary>
        /// Initialize the binding instance.
        /// </summary>
        private void Initialize(object target, string targetProperty, object source, Binding binding)
        {
            this.target = new WeakReference(target);
            this.source = new WeakReference(source);
            this.TargetProperty = targetProperty;
            this.Binding = binding;

            this.targetPropertyType = this.PropertyAccessor.GetPropertyType(target);
        }
Esempio n. 10
0
 public virtual void SetUp()
 {
     this.Binding = new Binding("Property1");
 }
Esempio n. 11
0
        /// <summary>
        /// Initialize the binding instance.
        /// </summary>
        private void Initialize(object target, string targetProperty, object source, Binding binding)
        {
            this.Target = target;
            this.Source = source;
            this.TargetProperty = targetProperty;
            this.Binding = binding;

            this.targetPropertyType = this.PropertyAccessor.GetPropertyType(target);
        }
 /// <summary>
 /// Sets a one-time binding between target and source.
 /// </summary>
 public static void OneTimeBind(this object target, string propertyName, IPropertyAccessor accessor, object source, Binding binding)
 {
     var expression = new BindingExpression(target, propertyName, accessor, source, binding);
     expression.Dispose();
 }
 /// <summary>
 /// Sets a one-time binding between target and source.
 /// </summary>
 public static void OneTimeBind(this object target, object source, Binding binding)
 {
     target.OneTimeBind(binding.PropertyName, source, binding);
 }
 /// <summary>
 /// Sets the binding between target and source.
 /// </summary>
 public static IBindingExpression AddBinding(this IPropertyInjection target, object source, Binding binding)
 {
     var scope = target.GetBindingScopeOrDefault();
     
     return scope.AddBinding(target, binding.PropertyName, source, binding);
 }