// todo: better way of changing binding source public static void ReplaceBindingSource(this object target, object source) { var key = target;//GetDictionaryKey(target); if (ExpressionDictionary.ContainsKey(key)) { var bindingExpressions = ExpressionDictionary[key]; var newExpressions = new List<BindingExpression>(); foreach (var expression in bindingExpressions) { var newExpression = new BindingExpression(target, expression.TargetProperty, source, expression.Binding); newExpressions.Add(newExpression); } ExpressionDictionary[key] = newExpressions; } }
/// <summary> /// Sets the binding between target and source. /// </summary> /// <returns> /// The binding expression. /// </returns> /// <param name='target'> /// The Target to bind to. /// </param> /// <param name='property'> /// The target Property to bind. /// </param> /// <param name='source'> /// The Source to bind to. /// </param> /// <param name='binding'> /// The source Binding. /// </param> public static BindingExpression SetBinding(this object target, string property, object source, Binding binding) { var expression = new BindingExpression(target, property, source, binding); var key = target;//GetDictionaryKey(target); if (!ExpressionDictionary.ContainsKey(key)) { ExpressionDictionary.Add(key, new List<BindingExpression>() { expression }); } else { ExpressionDictionary[key].Add(expression); } return expression; }