/// <summary> /// Binds two properties where both declaring types implement INotifyPropertyChanged. /// Supported BindingModes: OneWay, OneWayToSource, TwoWay /// </summary> /// <returns> /// The id of the binding which can be used to unbind source and target. /// </returns> public static BindingId Bind(BindableProperty source, BindableProperty target, BindingMode mode) { Contract.Requires(mode == BindingMode.OneWay || mode == BindingMode.OneWayToSource || mode == BindingMode.TwoWay, "BindingMode not supported: " + mode); var id = new BindingId(); if (mode == BindingMode.TwoWay || mode == BindingMode.OneWay) { id.Source = source.Owner; id.SourceBindingId = BindHandler(source, (s, e) => target.SetValue(source.GetValue())); } if (mode == BindingMode.TwoWay || mode == BindingMode.OneWayToSource) { id.Target = target.Owner; id.TargetBindingId = BindHandler(target, (s, e) => source.SetValue(target.GetValue())); } return(id); }
/// <summary> /// Removes the binding specified by the given id. /// </summary> public static void Unbind(BindingId id) { TryUnbind(id.Source, id.SourceBindingId); TryUnbind(id.Target, id.TargetBindingId); }