public BindingExpression(Binding binding, PropertyInfo targetProperty, object target)
		{
			if (binding == null)
				throw new ArgumentNullException("binding");

			if (targetProperty == null)
				throw new ArgumentNullException("targetProperty");

			if (target == null)
				throw new ArgumentNullException("target");

			Binding = binding;
			Binding.Target = target;
			TargetProperty = targetProperty;
			if(string.IsNullOrEmpty(binding.TargetPath))
			{
				binding.TargetPath = targetProperty.Name;
			}

			object source = Binding.Source;
			SourceProperty = source.GetType().GetNestedProperty(ref source, Binding.SourcePath, true);
			Binding.Source = source;
		}
Ejemplo n.º 2
0
		public BindAttribute(string sourcePath, string targetPath)
		{
			Binding = new Binding(sourcePath, targetPath);
		}
Ejemplo n.º 3
0
		public BindAttribute(string targetPath)
		{
			Binding = new Binding(null, targetPath);
		}
Ejemplo n.º 4
0
		public BindAttribute()
		{
			Binding = new Binding();
		}
Ejemplo n.º 5
0
		public IBindingExpression SetBinding(string targetProperty, Binding binding)
		{
			return SetBinding(this, targetProperty, binding);
		}
Ejemplo n.º 6
0
		public IBindingExpression SetBinding(IBindable target, string targetProperty, Binding binding)
		{
			return BindingOperations.SetBinding(target, targetProperty, binding);
		}
		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;
		}