public BindingExpression(Binding binding, MemberInfo 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 viewSource = Binding.Source; _ViewProperty = viewSource.GetType().GetNestedMember(ref viewSource, Binding.SourcePath, true); Binding.ViewSource = viewSource; var dataContext = viewSource as IDataContext; if (dataContext != null && dataContext.DataContext != null) { var source = dataContext.DataContext; SourceProperty = source.GetType().GetNestedMember(ref source, Binding.SourcePath, true); Binding.Source = source; } }
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; }
public BindAttribute(string sourcePath, string targetPath) { Binding = new Binding(sourcePath, targetPath); }
public BindAttribute(string sourcePath) { Binding = new Binding(sourcePath, "DataContext"); }
public BindAttribute() { Binding = new Binding(null, "DataContext"); }
public BindAttribute(string sourcePath) { Binding = new Binding(sourcePath, "Value"); }
public BindAttribute() { Binding = new Binding(null, "Value"); }
public Element(string caption, Binding binding): this(caption) { }