Example #1
0
        /// <summary>
        /// Cells for.
        /// </summary>
        /// <param name="This">The this.</param>
        /// <param name="item">The item.</param>
        /// <param name="selector">The selector.</param>
        /// <returns>Cell.</returns>
        /// <exception cref="System.InvalidOperationException">DataTemplate must be either a Cell or a View</exception>
        public static Cell CellFor(this BindableObject This, object item, DataTemplateSelector selector)
        {
            if (selector != null)
            {
                var template = selector.SelectTemplate(item, This);
                if (template != null)
                {
                    var templateInstance = template.CreateContent();
                    // see if it's a view or a cell
                    var templateView = templateInstance as View;
                    var templateCell = templateInstance as Cell;

                    if (templateView == null && templateCell == null)
                    {
                        throw new InvalidOperationException("DataTemplate must be either a Cell or a View");
                    }

                    if (templateView != null) // we got a view, wrap in a cell
                    {
                        templateCell = new ViewCell {
                            View = templateView
                        }
                    }
                    ;

                    return(templateCell);
                }
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Views for.
        /// </summary>
        /// <param name="This">The this.</param>
        /// <param name="item">The item.</param>
        /// <param name="selector">The selector.</param>
        /// <returns>View.</returns>
        /// <exception cref="System.InvalidOperationException">DataTemplate must be a View</exception>
        public static View ViewFor(this BindableObject This, object item, DataTemplateSelector selector)
        {
            if (selector != null)
            {
                var template = selector.SelectTemplate(item, This);
                if (template != null)
                {
                    var templateInstance = template.CreateContent();
                    // see if it's a view or a cell
                    var templateView = templateInstance as View;

                    if (templateView == null)
                    {
                        throw new InvalidOperationException("DataTemplate must be a View");
                    }

                    return(templateView);
                }
            }

            return(null);
        }