public MVVMBinding( MVVMBindingMode mode = MVVMBindingMode.Default, MVVMUpdateSourceTrigger updateSourceTrigger = MVVMUpdateSourceTrigger.Default, string path = null, object value = null, MVVMRelativeSource relativeSource = null, string elementName = null, MVVMControlBase element = null, bool validatesOnExceptions = false ) { if (element != null) { Type = MVVMBindingType.Element; } else if (elementName != null) { Type = MVVMBindingType.ElementName; } else if (relativeSource != null) { Type = MVVMBindingType.RelativeSource; } else if (value != null) { Type = MVVMBindingType.Value; } else { Type = MVVMBindingType.Path; } _Mode = mode; _UpdateSourceTrigger = updateSourceTrigger; Path = path; TargetValue = value; ElementName = elementName; Element = element; ValidatesOnExceptions = validatesOnExceptions; }
public MVVMBinding(MVVMControlBase element, string path, MVVMBindingMode mode, MVVMUpdateSourceTrigger updateSourceTrigger) : this(element, path, mode) { _UpdateSourceTrigger = updateSourceTrigger; }
internal void Bind(bool isForce = false) { MVVMAPI.Log("Bind {0}", this); if (!IsFirstBind && !isForce) { switch (Type) { case MVVMBindingType.Value: case MVVMBindingType.Element: case MVVMBindingType.ElementName: case MVVMBindingType.RelativeSource: MVVMAPI.Log("Denied Bind"); return; } } MVVMAPI.Log("Allow Bind"); Unbind(); IsFirstBind = false; switch (Type) { case MVVMBindingType.Value: break; case MVVMBindingType.Path: { object dataContext = null; if (IsDataContext) { if (Control.Parent != null) { dataContext = Control.Parent.DataContext.GetTargetValue(); } } else { dataContext = Control.DataContext.GetTargetValue(); } BindSource(dataContext); break; } case MVVMBindingType.Element: BindSource(Element); break; case MVVMBindingType.ElementName: { MVVMControlBase control; Control.Root.NamedControls.TryGetValue(ElementName, out control); BindSource(control); break; } case MVVMBindingType.RelativeSource: { MVVMControlBase control = Control; switch (RelativeSource.Mode) { case MVVMRelativeSourceMode.Self: break; case MVVMRelativeSourceMode.FindAncestor: int ancestorCount = 0; while (control != null) { if (RelativeSource.AncestorType == null || RelativeSource.AncestorType.IsInstanceOfType(control)) { ancestorCount++; if (ancestorCount == RelativeSource.AncestorLevel) { break; } } control = control.Parent; } break; default: throw new NotImplementedException(RelativeSource.Mode.ToString()); } BindSource(control); break; } default: throw new NotImplementedException(Type.ToString()); } BlockOnChanged++; OneWaySetTargetValue(); BlockOnChanged--; }
public MVVMBinding(MVVMControlBase element, string path, MVVMBindingMode mode) : this(element, path) { _Mode = mode; }
public MVVMBinding(MVVMControlBase element, string path) : this(element) { Path = path; }
public MVVMBinding(MVVMControlBase element, MVVMUpdateSourceTrigger updateSourceTrigger) : this(element) { _UpdateSourceTrigger = updateSourceTrigger; }
public MVVMBinding(MVVMControlBase element, MVVMBindingMode mode) : this(element) { _Mode = mode; }
public MVVMBinding(MVVMControlBase element) { Element = element; Type = MVVMBindingType.Element; }