// public static IRoot CreateRootElementFromObject(Type elementType, object obj) // { // elementType = elementType ?? typeof(RootElement); // // object context = obj; // MemberInfo dataContextMember = GetMemberFromDataContext(member, ref context); // var items = dataContextMember.GetValue(context); // // var rootElement = Activator.CreateInstance(elementType) as IElement; // // ((Element)rootElement).Opaque = false; // rootElement.Caption = caption; // rootElement.Theme = Theme.CreateTheme(Root.Theme); // rootElement.ViewBinding.MemberInfo = dataContextMember; // rootElement.ViewBinding.ElementType = elementType; // rootElement.ViewBinding.ViewType = viewType; // rootElement.ViewBinding.DataContextCode = DataContextCode.Object; // rootElement.Theme.CellStyle = GetCellStyle(member, UITableViewCellStyle.Default); // // if (cellEditingStyle != null) // rootElement.EditingStyle = cellEditingStyle.EditingStyle; // // if (items != null) // { // if (items is UIView) // { // rootElement.ViewBinding.View = items as UIView; // } // else // { // rootElement.DataContext = items; // } // } // else // rootElement.DataContext = context; // // if (genericType != null) // { // SetDefaultConverter(view, member, "DataContext", new EnumerableConverter(), null, bindings); // rootElement.ViewBinding.DataContextCode = DataContextCode.ViewEnumerable; // rootElement.ViewBinding.ViewType = viewType; // } // // if (isList) // { // var innerRoot = BindingContext.CreateRootedView(rootElement as IRoot); // root = innerRoot as IElement; // } // else // { // root = rootElement; // } // } private static IRoot CreateObjectRoot(IRoot root) { IRoot newRoot = null; UIView view = null; object context = root.DataContext; if (root.ViewBinding.View != null) { view = root.ViewBinding.View; if (root.ViewBinding.MemberInfo != null && root.ViewBinding.DataContext != null) { var memberValue = root.ViewBinding.MemberInfo.GetValue(root.ViewBinding.DataContext) as UIView; if (memberValue != null) view = memberValue; } } else { if (root.ViewBinding.ViewType != null) { view = Activator.CreateInstance(root.ViewBinding.ViewType) as UIView; } } var dataContext = view as IDataContext; if (dataContext != null) { dataContext.DataContext = context; var lifetime = context as IInitializable; if (lifetime != null) lifetime.Initialize(); lifetime = dataContext as IInitializable; if (lifetime != null) lifetime.Initialize(); } var bindingContext = new BindingContext(view, root.Caption, root.Theme); newRoot = (IRoot)bindingContext.Root; newRoot.ViewBinding = root.ViewBinding; newRoot.ViewBinding.View = view; return newRoot; }
public DialogViewController(UIView view, bool pushing) : base(UITableViewStyle.Grouped) { RootView = view; var title = string.Empty; var vw = RootView as IView; if (vw != null) title = vw.Caption; var bindingContext = new BindingContext(RootView, title); _Pushing = pushing; PrepareRoot(bindingContext.Root); }
protected override void OnDataContextChanged() { base.OnDataContextChanged(); if (ElementView is IView && ElementView != null) { var binding = new BindingContext(ElementView, Caption, Theme); if (binding.Root != null) { Sections = binding.Root.Sections; } } else if (DataContext != null && DataContext is IEnumerable && ViewBinding.ElementType != null) { Sections.Clear(); var section = BindingContext.CreateSection(this, null, DataContext, ViewBinding.ElementType, false); Sections.Add(section); } }
public DialogViewController(string title, UIView view, bool pushing) : base(UITableViewStyle.Grouped) { RootView = view; var bindingContext = new BindingContext(RootView, title); _Pushing = pushing; PrepareRoot(bindingContext.Root); }