public void Add(BindingNode node) { if (node != null) { _nodes.Add(node); } }
/// <summary> /// This method is called to process all bindings for a Localize /// instance that is bound (i.e. has a binding defined or contain /// one or more Localize children). /// </summary> /// <param name="value"></param> /// <param name="parent"></param> /// <param name="bindings"></param> /// <remarks> /// The method is called recursively for all child that has one or /// more children Localize instance /// </remarks> private void ProcessBindings(object value, ref BindingNode parent, ref Collection <Binding> bindings) { BindingNode wrapper; BindingNode node = CreateBindingNode(this, value, bindings.Count); MultiBinding multiBinding = CreateMultiBinding(this, value); if (parent == null) // is root node? { parent = new BindingNode(multiBinding); wrapper = parent; } else { wrapper = new BindingNode(multiBinding); parent.Add(wrapper); } bindings.Add(node.Binding); multiBinding.Bindings.Add(node.Binding); wrapper.Add(node); foreach (Localize child in _children) { // Children instances have no target: the root Localize // instance is used to evaluate the nested child's value (if any) object childValue = GetValue(child, child.Key); if (child.HasChildren) { child.ProcessBindings(childValue, ref wrapper, ref bindings); } else { if (child.HasBinding) { // Recursive call var childNode = CreateBindingNodeWrapper(child, childValue, bindings); wrapper.Add(childNode); } else { var childNode = CreateBindingNode(child, childValue, bindings.Count); bindings.Add(childNode.Binding); multiBinding.Bindings.Add(childNode.Binding); wrapper.Add(childNode); } } } }
/// <summary> /// Create a wrapper on a child instance that has no children /// </summary> /// <param name="instance"></param> /// <param name="value"></param> /// <param name="bindings"></param> /// <returns>The <see cref="BindingNode"/> wrapper instance</returns> private BindingNode CreateBindingNodeWrapper(Localize instance, object value, Collection <Binding> bindings) { Binding binding = CloneBindingOf(instance); MultiBinding multiBinding = CreateMultiBinding(instance, value); multiBinding.Bindings.Add(binding); var node = new BindingNode(multiBinding); node.Add(new BindingNode(binding, bindings.Count)); // Must add after the new node is created to match index correctly bindings.Add(binding); return(node); }
/// <summary> /// Generate a wrapper on a hierarchy of binding nodes instance /// The wrapper is a <see cref="MultiBinding"/> instance with a converter /// that process the bindings resolved value using the given nodes /// </summary> /// <param name="value"></param> /// <returns>A <see cref="MultiBinding"/> instance</returns> private MultiBinding CreateMultiBindingWrapper(object value) { BindingNode root = null; var bindings = new Collection <Binding>(); ProcessBindings(value, ref root, ref bindings); var wrapper = new MultiBinding(); foreach (var binding in bindings) { wrapper.Bindings.Add(binding); } wrapper.TargetNullValue = GetTargetNullValue(this); wrapper.Converter = new BindingNodeConverter(root); return(wrapper); }
private object GetMultiBindingValue(BindingNode node, object[] values, Type targetType, CultureInfo culture) { if (IsPropertyUnset(values)) { return(null); } if (node.MultiBinding == null) { throw new NullReferenceException("The MultiBinding reference is null."); } var multiBinding = node.MultiBinding; // Recursive call for MultiBinding nodes var objects = node.Nodes.Select(x => x.MultiBinding != null ? GetMultiBindingValue(x as BindingNode, values, targetType, culture) : values[x.Index]).ToArray(); return(multiBinding.Converter.Convert(objects, targetType, null, multiBinding.ConverterCulture ?? culture)); }
public BindingNodeConverter(BindingNode root) { _root = root; }