private static object GetActualView(object view)
        {
            if (view != null && !(view is IView))
            {
                var type       = view.GetType();
                var actualView = ViewContainer.GetExactView(type);

                if (actualView == null)
                {
                    var viewAttribute = type.GetCustomAttribute <ViewAttribute>();
                    if (viewAttribute != null)
                    {
                        actualView = viewAttribute.ViewType;
                    }
                }

                if (actualView != null)
                {
                    var newView = Activator.CreateInstance(actualView);
                    var dc      = newView as IDataContext <object>;
                    if (dc != null)
                    {
                        dc.DataContext = view;
                    }

                    return(newView);
                }
            }

            return(view);
        }
Beispiel #2
0
        protected override UITableViewCell NewCell(NSString cellId, NSIndexPath indexPath)
        {
            var id = cellId;

            var memberData = GetMemberData(indexPath);

            if (memberData != null)
            {
                id = memberData.Id;
            }

            var section    = Sections[indexPath.Section];
            var listSource = GetListSource(indexPath);

            if ((typeof(IEnumerable).IsAssignableFrom(memberData.Type) || typeof(Enum).IsAssignableFrom(memberData.Type)) && listSource != null && !listSource.IsRootCell)
            {
                id = listSource.CellId;
            }

            if (memberData != null)
            {
                var viewType = ViewContainer.GetView(memberData);
                if (viewType != null)
                {
                    var key = id.ToString();

                    if (section.ViewTypes.ContainsKey(key))
                    {
                        var viewTypeList = section.ViewTypes[key];

                        if (viewTypeList == null)
                        {
                            viewTypeList           = new List <Type>();
                            section.ViewTypes[key] = viewTypeList;

                            if (!viewTypeList.Contains(viewType))
                            {
                                viewTypeList.Add(viewType);
                            }
                        }
                    }
                    else
                    {
                        section.ViewTypes.Add(key, new List <Type>()
                        {
                            viewType
                        });
                    }
                }
            }

            return(base.NewCell(id, indexPath));
        }
Beispiel #3
0
        public void NavigateToView()
        {
            var viewType = NavigationViewType;

            if (viewType == null)
            {
                viewType = ViewContainer.GetView(SelectedItem.GetType());
            }

            if (viewType != null)
            {
                var disposable = NavigationView as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }

                NavigationView = Activator.CreateInstance(viewType);

                var dc = NavigationView as IDataContext <object>;
                if (dc != null)
                {
                    dc.DataContext = SelectedItem;
                }
                else
                {
                    NavigationView = SelectedItem;
                }

                var initializable = NavigationView as IInitializable;
                if (initializable != null)
                {
                    initializable.Initialize();
                }

                Caption = SelectedItem.ToString();

                var dvc = new DialogViewController(Caption, NavigationView, Controller.Theme, true);
                Controller.NavigationController.PushViewController(dvc, true);
            }
        }
Beispiel #4
0
        public static void InitializeViewContainer()
        {
            //Integral types
            ViewContainer.RegisterView(typeof(sbyte), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(byte), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(char), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(short), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(ushort), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(int), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(uint), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(long), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(ulong), typeof(StringCellView));

            //float types
            ViewContainer.RegisterView(typeof(float), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(double), typeof(StringCellView));
            ViewContainer.RegisterView(typeof(decimal), typeof(StringCellView));

            //bool
            ViewContainer.RegisterView(typeof(bool), typeof(BooleanCellView));

            //Reference types
            ViewContainer.RegisterView(typeof(object), typeof(ObjectCellView <object>));
            ViewContainer.RegisterView(typeof(string), typeof(StringCellView));

            //Enum
            ViewContainer.RegisterView(typeof(Enum), typeof(ListCellView));

            //IEnumerable
            ViewContainer.RegisterView(typeof(IEnumerable), typeof(ListCellView));
            ViewContainer.RegisterView(typeof(IEnumerable <object>), typeof(ListCellView));

            //Other
            ViewContainer.RegisterView(typeof(UIView), typeof(ObjectCellView <UIView>));
            ViewContainer.RegisterView(typeof(ICommand), typeof(CommandCellView));
            ViewContainer.RegisterView(typeof(DateTime), typeof(DateCellView));
            ViewContainer.RegisterView(typeof(NSDate), typeof(DateCellView));
        }
Beispiel #5
0
 public CellViewTemplate()
 {
     ViewContainer.RegisterView(GetType(), CellViewType);
 }
Beispiel #6
0
 public CellViewTemplate(Type valueConverterType) : base(valueConverterType)
 {
     ViewContainer.RegisterView(GetType(), CellViewType);
 }
 public static void InitializeViewContainer()
 {
     ViewContainer.RegisterView(typeof(Uri), typeof(HtmlCellView));
     ViewContainer.RegisterView(typeof(CLLocationCoordinate2D), typeof(MapCellView));
     ViewContainer.RegisterView(typeof(IEnumerable <CLLocationCoordinate2D>), typeof(MapCellView));
 }
Beispiel #8
0
        public void NavigateToList()
        {
            var section = Sections[0];
            var data    = GetSectionData(0);

            if (string.IsNullOrEmpty(Caption))
            {
                Caption = data.ToString();
            }

            var dvc = new DialogViewController(Caption, null, Controller.Theme, true)
            {
                ToolbarButtons = null, NavbarButtons = null
            };

            if (NavigationSource == null)
            {
                NavigationSource = new ListSource(dvc, data, section.ViewTypes[CellId]);
            }

            NavigationSource.SelectionAction = SelectionAction;

            NavigationSource.IsSelectable       = (SelectionAction == SelectionAction.PopOnSelection || SelectionAction == SelectionAction.Selection || SelectionAction == SelectionAction.Multiselection);
            NavigationSource.NavigationViewType = null;

            var viewType = NavigationViewType;

            if (viewType == null && SelectionAction == SelectionAction.NavigateToView)
            {
                var genericType = data.GetType().GetGenericArguments().FirstOrDefault();
                viewType = ViewContainer.GetView(genericType);
            }

            if (viewType != null)
            {
                NavigationSource.IsNavigable        = viewType == typeof(ObjectCellView <object>);
                NavigationSource.NavigationViewType = viewType;
            }

            NavigationSource.IsNavigable = !PopOnSelection && NavigationSource.IsNavigable && SelectionAction != SelectionAction.Custom;

            NavigationSource.CellFactory = CellFactory;

            NavigationSource.SelectedItem        = SelectedItem;
            NavigationSource.SelectedItems       = SelectedItems;
            NavigationSource.UnselectionBehavior = UnselectionBehavior;

            NavigationSource.IsMultiselect = IsMultiselect;
            //		NavigationSource.IsSelectable = IsSelectable;

            if (data.Count > 0 && (data[0].GetType().IsPrimitive || data[0].GetType().IsEnum))
            {
                NavigationSource.IsSelectable = true;
            }

            NavigationSource.PopOnSelection = PopOnSelection;
            NavigationSource.NibName        = NibName;

            NavigationSource.TableViewStyle = TableViewStyle;

            NavigationSource.IsSearchbarHidden = IsSearchbarHidden;
            NavigationSource.EnableSearch      = EnableSearch;
            NavigationSource.IncrementalSearch = IncrementalSearch;
            NavigationSource.SearchPlaceholder = SearchPlaceholder;
            NavigationSource.SearchCommand     = SearchCommand;

            NavigationSource.SelectedAccessoryViewType   = SelectedAccessoryViewType;
            NavigationSource.UnselectedAccessoryViewType = UnselectedAccessoryViewType;

            NavigationSource.MemberData = new MemberData(MemberData.Source, MemberData.Member);

            if (NavigationSource.NavigationViewType != null)
            {
                var rowHeightAttribute = NavigationSource.NavigationViewType.GetCustomAttribute <RowHeightAttribute>();
                if (rowHeightAttribute != null)
                {
                    NavigationSource.MemberData.RowHeight = rowHeightAttribute.RowHeight;
                }
            }

            NavigationSource.Controller = dvc;
            dvc.TableView.Source        = NavigationSource;
            Controller.NavigationController.PushViewController(dvc, true);
        }