public static void SetBinding (DependencyObject source, string path, IDependencyProperty target, IValueConverter converter = null) { var paths = path.Split ('.'); BindingExpression expression = new PropertyExpression (source.GetProperty (paths [0])); foreach (var p in paths.Skip(1)) { expression = new PathExpression (expression, p); } new Binding (expression, new PropertyExpression (target), converter ?? new EmptyConverter ()); }
public static void SetBinding(DependencyObject source, string path, IDependencyProperty target, IValueConverter converter = null) { var paths = path.Split('.'); BindingExpression expression = new PropertyExpression(source.GetProperty(paths [0])); foreach (var p in paths.Skip(1)) { expression = new PathExpression(expression, p); } new Binding(expression, new PropertyExpression(target), converter ?? new EmptyConverter()); }
public PropertyExpression (PathExpression expression, string propertyName) { PropertyName = propertyName; Source = expression.Property; if (Source != null) { if (Source.Value != null) Property = (Source.Value as DependencyObject).GetProperty (propertyName); Source.DependencyPropertyValueChanged += HandlePropertyValueChanged; } expression.GetProperty ("Property").DependencyPropertyValueChanged += HandlePropertyChanged; }
public Binding (PathExpression source, PathExpression target, IValueConverter converter) { Source = source; Target = target; Converter = converter; SourceProperty = Source.Property; TargetProperty = Target.Property; Source.GetProperty ("Property").DependencyPropertyValueChanged += HandleSourcePropertyChanged; Target.GetProperty ("Property").DependencyPropertyValueChanged += HandleTargetPropertyChanged; UpdateTargetValue (); if (SourceProperty != null) SourceProperty.DependencyPropertyValueChanged += HandleSourceValueChanged; if (TargetProperty != null) TargetProperty.DependencyPropertyValueChanged += HandleTargetValueChanged; }
public AttachedPropertyExpression (PathExpression expression, object item, string propertyName) { PropertyName = propertyName; Item = item; Source = expression.Property; if (Source != null) { var container = Source.Value as IAttachedPropertiesContainer; if (container != null) { Property = container.GetProperty (item, propertyName); container.AddedItem += HandleAddedItem; container.RemovedItem += HandleRemovedItem; } Source.DependencyPropertyValueChanged += HandlePropertyValueChanged; } expression.GetProperty ("Property").DependencyPropertyValueChanged += HandlePropertyChanged; }