public static void BindSize(this VisualTreeElement element, XmlNode node, Control root) { XmlAttribute height = node.Attribute("Height"); if (height != null) { if (height.IsBinding()) { throw new NotImplementedException(); } else { element.Widget.HeightRequest = int.Parse(height.Value); } } XmlAttribute width = node.Attribute("Widght"); if (width != null) { if (width.IsBinding()) { throw new NotImplementedException(); } else { element.Widget.WidthRequest = int.Parse(width.Value); } } }
public static void BindExpand(this VisualTreeElement element, XmlNode node, Control root) { XmlAttribute hexpand = node.Attribute("HorizontalExpansion"); if (hexpand != null) { if (hexpand.IsBinding()) { throw new NotImplementedException(); } else { element.Widget.Hexpand = bool.Parse(hexpand.Value); } } XmlAttribute vexpand = node.Attribute("VerticalExpansion"); if (vexpand != null) { if (vexpand.IsBinding()) { throw new NotImplementedException(); } else { element.Widget.Vexpand = bool.Parse(vexpand.Value); } } }
public static void BindWidgetProperties(this VisualTreeElement element, XmlNode node, Control root) { element.BindMargin(node, root); element.BindAlignment(node, root); element.BindExpand(node, root); element.BindSize(node, root); }
public static void BindCollection(this VisualTreeElement element, BindableCollectionAttribute attribute, XmlNode node) { Type elementType = element.GetType(); XmlAttribute templateAttribute = node.Attribute(attribute.TemplateProperty); XmlAttribute sourceAttribute = node.Attribute(attribute.Source); if (sourceAttribute == null ^ templateAttribute == null) { throw new ArgumentException("Bindable collection source or template undefined."); } if (sourceAttribute == null) { return; } PropertyInfo property = elementType.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Single(p => p.Name == attribute.TemplateProperty); property.SetValue(element, templateAttribute.Value); Action <string, dynamic> adder = elementType .GetMethod(attribute.AdderName) .CreateDelegate(typeof(Action <string, dynamic>), element) as Action <string, dynamic>; Action <string, dynamic> remover = elementType .GetMethod(attribute.RemoverName) .CreateDelegate(typeof(Action <string, dynamic>), element) as Action <string, dynamic>; element.BindingContext.BindCollection(remover, adder, sourceAttribute.BindingExpression()); }
public static void BindAlignment(this VisualTreeElement element, XmlNode node, Control root) { XmlAttribute halign = node.Attribute("HorizontalAlignment"); if (halign != null) { if (halign.IsBinding()) { throw new NotImplementedException(); } else { element.Widget.Halign = (Align)Enum.Parse(typeof(Align), halign.Value); } } XmlAttribute valign = node.Attribute("VerticalAlignment"); if (valign != null) { if (valign.IsBinding()) { throw new NotImplementedException(); } else { element.Widget.Valign = (Align)Enum.Parse(typeof(Align), valign.Value); } } }
public static void Bind(this VisualTreeElement element, XmlNode node) { Type elementType = element.GetType(); if (elementType.HasAttribute <BindableCollectionAttribute>()) { BindCollection(element, elementType.GetCustomAttribute <BindableCollectionAttribute>(), node); } foreach (MemberInfo bindableProperty in elementType.MembersWithAttribute <BindablePropertyAttribute>(BindingFlags.Public | BindingFlags.Instance)) { if (node.Attribute(bindableProperty.Name) != null) { element.BindProperty((PropertyInfo)bindableProperty, bindableProperty.GetCustomAttribute <BindablePropertyAttribute>(), node.Attribute(bindableProperty.Name).BindingExpression()); } } foreach (MemberInfo bindableEvent in elementType.MembersWithAttribute <BindableEventAttribute>(BindingFlags.Public | BindingFlags.Instance)) { if (node.Attribute(bindableEvent.Name) != null) { element.BindEvent(bindableEvent, node.Attribute(bindableEvent.Name).BindingExpression()); } } }
public static VisualTreeElement Serialize(View view, Type control, XmlNode node) { VisualTreeElement element = (VisualTreeElement)Activator.CreateInstance(control); element.BindingContext = view.BindingContext; element.Bind(node); return(element); }
public static void BindEvent(this VisualTreeElement element, MemberInfo elementEvent, BindingExpression binding) { PropertyInfo viewChangeHandler = element.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Single(p => p.Name == elementEvent.Name); Action <Action> subscriber = handler => { Action current = (Action)viewChangeHandler.GetValue(element); current += handler; viewChangeHandler.SetValue(element, current); }; element.BindingContext.BindCommand(subscriber, elementEvent.Name, binding.Target); }
public static void BindMargin(this VisualTreeElement element, XmlNode node, Control root) { XmlAttribute attribute = node.Attribute("Margin"); if (attribute != null) { if (attribute.IsBinding()) { Action <EventHandler> subscribe = func => { }; root.BindingContext.BindProperty( subscribe, () => element.Widget.MarginString(), value => element.Widget.SetMargin((string)value), "Margin", attribute.Value); } else { element.Widget.SetMargin(attribute.Value); } } }
public static void BindProperty(this VisualTreeElement element, PropertyInfo elementProperty, BindablePropertyAttribute attribute, BindingExpression binding) { if (!binding.IsDatabound) { elementProperty.SetValue(element, BindingConverter.ConvertBindingValue(elementProperty.PropertyType, binding.Source)); return; } Action <Action> subscriber; BindingMode mode; if (string.IsNullOrEmpty(attribute.ChangeHandler)) { subscriber = handler => { }; mode = BindingMode.FromViewModel; } else { PropertyInfo viewChangeHandler = element.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Single(p => p.Name == attribute.ChangeHandler); subscriber = handler => { Action current = (Action)viewChangeHandler.GetValue(element); current += handler; viewChangeHandler.SetValue(element, current); }; mode = BindingMode.TwoWay; } element.BindingContext.BindProperty( subscriber, elementProperty.CreateGetDelegate <dynamic>(element), elementProperty.CreateSetDelegate <dynamic>(element), elementProperty.Name, binding.Target, mode); }
public VisualTreeElement AddChild(VisualTreeElement element) { return(base.AddChild(element)); }
public override void AddControl(VisualTreeElement element) { table.Controls.Add(element.Control); AddToTable(element.Control); base.AddChildren(element); }
public abstract void AddControl(VisualTreeElement element);