예제 #1
0
        public IElement CreateEnumerableRoot(MemberInfo member, string caption, object view, List <Binding> bindings)
        {
            SetDefaultConverter(member, "Value", new EnumerableConverter(), bindings);

            var rootAttribute = member.GetCustomAttribute <RootAttribute>();
            var listAttribute = member.GetCustomAttribute <ListAttribute>();

            var items = (IEnumerable)GetValue(member, view);

            var element = new RootElement(caption);

            element.ViewBinding.DataContext     = view;
            element.ViewBinding.MemberInfo      = member;
            element.ViewBinding.DataContext     = items;
            element.ViewBinding.DataContextCode = DataContextCode.Enumerable;

            var dataTemplate = view as IDataTemplate;

            if (dataTemplate != null)
            {
                rootAttribute = dataTemplate.CustomAttributes.FirstOrDefault((o) => o.GetType() == typeof(RootAttribute)) as RootAttribute;
                listAttribute = dataTemplate.CustomAttributes.FirstOrDefault((o) => o.GetType() == typeof(ListAttribute)) as ListAttribute;
            }

            if (rootAttribute != null)
            {
                element.ViewBinding.ViewType = rootAttribute.ViewType;
            }

            if (listAttribute != null)
            {
                element.ViewBinding.ViewType = listAttribute.ViewType ?? element.ViewBinding.ViewType;
            }

            if (element.ViewBinding.ViewType != null)
            {
                dataTemplate = new StandardListView()
                {
                    Items = items
                };

                List <object> customAttributes = new List <object>(member.GetCustomAttributes(false));
                var           propertyInfo     = dataTemplate.GetType().GetProperty("Items");
                var           itemAttributes   = propertyInfo.GetCustomAttributes(false);
                customAttributes.AddRange(itemAttributes);
                dataTemplate.CustomAttributes = customAttributes;

                element.ViewBinding.DataContext     = dataTemplate;
                element.ViewBinding.DataContextCode = DataContextCode.Object;
                element.ViewBinding.MemberInfo      = propertyInfo;
            }

            element.Theme.CellStyle = GetCellStyle(member, UITableViewCellStyle.Default);

            return(element);
        }
예제 #2
0
		public IElement CreateEnumerableRoot(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			SetDefaultConverter(member, "Value", new EnumerableConverter(), bindings);

			var rootAttribute = member.GetCustomAttribute<RootAttribute>();
			var listAttribute = member.GetCustomAttribute<ListAttribute>();
			
			var items = (IEnumerable)GetValue(member, view);
			
			var element = new RootElement(caption);
			element.ViewBinding.DataContext = view;
			element.ViewBinding.MemberInfo = member;
			element.ViewBinding.DataContext = items;
			element.ViewBinding.DataContextCode = DataContextCode.Enumerable;
 
			var dataTemplate = view as IDataTemplate;
			if (dataTemplate != null)
			{
				rootAttribute = dataTemplate.CustomAttributes.FirstOrDefault((o)=>o.GetType() == typeof(RootAttribute)) as RootAttribute;
				listAttribute = dataTemplate.CustomAttributes.FirstOrDefault((o)=>o.GetType() == typeof(ListAttribute)) as ListAttribute;
			}
			
			if (rootAttribute != null)
			{
				element.ViewBinding.ViewType = rootAttribute.ViewType;
			}

			if (listAttribute != null)
			{
				element.ViewBinding.ViewType = listAttribute.ViewType ?? element.ViewBinding.ViewType;
			}

			if (element.ViewBinding.ViewType != null)
			{
				dataTemplate = new StandardListView() { Items = items };
				
				List<object> customAttributes = new List<object>(member.GetCustomAttributes(false));
				var propertyInfo = dataTemplate.GetType().GetProperty("Items");
				var itemAttributes = propertyInfo.GetCustomAttributes(false);
				customAttributes.AddRange(itemAttributes);
				dataTemplate.CustomAttributes = customAttributes;
				
				element.ViewBinding.DataContext = dataTemplate;
				element.ViewBinding.DataContextCode = DataContextCode.Object;
				element.ViewBinding.MemberInfo = propertyInfo;
			}

			element.Theme.CellStyle = GetCellStyle(member, UITableViewCellStyle.Default);

			return element;
		}