Пример #1
0
        private ISection CreateSelectCollectionSection(MemberInfo member, string caption, object view, List <Binding> bindings)
        {
            object context = view;

            var csection = new Section()
            {
                IsMultiselect = false, Opaque = false
            };
            var index = 0;

            SetDefaultConverter(view, member, "DataContext", new EnumerableConverter(), null, bindings);

            var dataContextMember = GetMemberFromDataContext(member, ref context);

            var collection = dataContextMember.GetValue(context) as IEnumerable;

            foreach (var item in collection)
            {
                var radioElement = new RadioElement(item.ToString())
                {
                    Item = item, Index = index, DataContext = false
                };

                csection.Add(radioElement);
                index++;
            }

            csection.ViewBinding.DataContextCode = DataContextCode.Enumerable;
            csection.ViewBinding.ViewType        = null;

            return(csection);
        }
Пример #2
0
 public void UpdateSelected(RadioElement element, bool selected)
 {
     if (element != null)
     {
         element.DataContext = selected;
         element.UpdateSelected();
     }
 }
Пример #3
0
 public void UpdateSelected(RadioElement element, bool selected)
 {
     if (element != null)
     {
         element.Value = selected;
         element.UpdateSelected();
     }
 }
Пример #4
0
        public static ISection CreateEnumSection(IRoot root, IEnumerable values, object currentValue, bool popOnSelection)
        {
            var csection = new Section()
            {
                Opaque = false
            };

            int index    = 0;
            int selected = 0;

            ApplyElementTheme(root.Theme, csection, null);

            foreach (var value in values)
            {
                if (currentValue == value)
                {
                    selected = index;
                }

                var description = value.ToString();

                if (value.GetType() == typeof(Enum))
                {
                    description = ((Enum)value).GetDescription();
                }

                var radioElement = new RadioElement(description)
                {
                };
                radioElement.Index       = index;
                radioElement.PopOnSelect = popOnSelection;
                radioElement.Value       = selected == index;
                radioElement.Opaque      = false;

                ApplyElementTheme(root.Theme, radioElement, null);

                csection.Add(radioElement);
                index++;
            }

            csection.Parent = root as IElement;

            return(csection);
        }
Пример #5
0
        private ISection CreateEnumSection(Theme theme, MemberInfo member, IEnumerable values, object currentValue, bool popOnSelection, List <Binding> bindings)
        {
            var csection = new Section()
            {
                Opaque = false
            };

            int index    = 0;
            int selected = -1;

            foreach (var value in values)
            {
                if (currentValue != null && currentValue.Equals(value))
                {
                    selected = index;
                }

                var description = value.ToString();

                if (value.GetType().IsEnum)
                {
                    description = ((Enum)value).GetDescription();
                }

                var radioElement = new RadioElement(description)
                {
                    Item = value
                };
                radioElement.Index       = index;
                radioElement.PopOnSelect = popOnSelection;
                radioElement.DataContext = selected == index;
                radioElement.Opaque      = false;

                csection.Add(radioElement);
                index++;
            }

            csection.ViewBinding.DataContextCode = DataContextCode.Enum;

            return(csection);
        }
Пример #6
0
		public void UpdateSelected(RadioElement element, bool selected)
		{
			if (element != null)
			{
				element.Value = selected;
				element.UpdateSelected();
			}
		}
Пример #7
0
        private List <ISection> CreateSectionList(object view, IRoot root)
        {
            var memberFuncMap = new List <Func <object, MemberInfo[]> >()
            {
                (T) => GetFields(T),
                (T) => GetProperties(T),
                (T) => GetMethods(T)
            };

            ISection lastSection = new Section()
            {
                Order = -1, Parent = root as IElement
            };

            var sectionList = new List <ISection>()
            {
                lastSection
            };

            IElement newElement = null;
            Theme    theme      = null;
            var      themeable  = root as IThemeable;

            if (themeable != null)
            {
                ApplyRootTheme(view, themeable);
                theme = themeable.Theme;
                ApplyElementTheme(theme, lastSection, null);
            }

            foreach (var memberFunc in memberFuncMap)
            {
                var members = memberFunc(view);

                foreach (var member in members)
                {
                    var pullToRefreshAttribute = member.GetCustomAttribute <PullToRefreshAttribute>();
                    if (pullToRefreshAttribute != null)
                    {
                        root.PullToRefreshCommand = GetCommandForMember(view, member);
                        root.DefaultSettingsKey   = pullToRefreshAttribute.SettingsKey;
                    }
                    var skipAttribute = member.GetCustomAttribute <SkipAttribute>(true);
                    if (skipAttribute != null)
                    {
                        continue;
                    }

                    var inline = member.GetCustomAttribute <InlineAttribute>() != null;
                    //	var isRoot = member.GetCustomAttribute<RootAttribute>() != null;
                    var listAttribute    = member.GetCustomAttribute <ListAttribute>();
                    var isList           = listAttribute != null;
                    var sectionAttribute = member.GetCustomAttribute <SectionAttribute>();

                    if (sectionAttribute != null)
                    {
                        Theme sectionTheme = null;
                        if (sectionAttribute.ThemeType != null)
                        {
                            sectionTheme = Activator.CreateInstance(sectionAttribute.ThemeType) as Theme;
                        }

                        lastSection = new Section(sectionAttribute.Caption, sectionAttribute.Footer)
                        {
                            Order = sectionAttribute.Order
                        };
                        lastSection.Parent = root as IElement;
                        ApplyElementTheme(root.Theme, lastSection, null);

                        ApplyElementTheme(sectionTheme, lastSection, null);
                        sectionList.Add(lastSection);
                    }

                    newElement = GetElementForMember(view, member);

                    if (newElement != null)
                    {
                        newElement.Theme.MergeTheme(root.Theme);
                        ApplyElementTheme(root.Theme, newElement, member);

                        //var context = newElement as IView;
                        //	var displayInline = (inline || !isRoot) && newElement is IRoot; //&& context != null;

                        if (isList)
                        {
                            var  newRoot  = newElement as IRoot;
                            Type viewType = newRoot.ViewBinding.ViewType ?? listAttribute.ViewType;

                            string caption = null;
                            if (!(view is IDataTemplate))
                            {
                                caption = newElement.Caption;
                            }

                            lastSection = new Section(caption, null)
                            {
                            };
                            lastSection.Parent = root as IElement;
                            ApplyElementTheme(root.Theme, lastSection, null);
                            sectionList.Add(lastSection);

                            IEnumerable datacontext = null;
                            if (view is IDataTemplate)
                            {
                                datacontext = ((IDataTemplate)view).Items;
                            }
                            else
                            {
                                datacontext = (IEnumerable)GetValue(member, view);
                            }

                            foreach (var e in datacontext)
                            {
                                IElement element = null;

                                if (e is IViewModel)
                                {
                                    element = new RootElement(e.ToString());
                                    element.ViewBinding.ViewType    = viewType;
                                    element.ViewBinding.DataContext = e;

                                    ((IRoot)element).Theme = Theme.CreateTheme(root.Theme);
                                    element.Theme          = ((IRoot)element).Theme;

                                    if (listAttribute.ThemeType != null)
                                    {
                                        var listTheme = Activator.CreateInstance(listAttribute.ThemeType) as Theme;
                                        var rootTheme = Theme.CreateTheme(((IRoot)element).Theme);
                                        rootTheme.MergeTheme(listTheme);
                                        ((IRoot)element).Theme = rootTheme;
                                    }
                                }
                                else
                                {
                                    element       = new RadioElement(e.ToString());
                                    element.Theme = ((IRoot)element).Theme;
                                }

                                lastSection.Add(element);
                            }
                        }
                        else if (inline)
                        {
                            var inlineSection = new Section(string.Empty, null)
                            {
                            };
                            ApplyElementTheme(newElement.Theme, inlineSection, null);
                            inlineSection.Parent = root as IElement;
                            sectionList.Add(inlineSection);

                            IRoot inlineRoot = newElement as IRoot;
                            if (newElement.ViewBinding.DataContextCode == DataContextCode.Object)
                            {
                                var bindingContext = new BindingContext(newElement.ViewBinding.CurrentView, newElement.Caption, newElement.Theme);
                                inlineRoot = bindingContext.Root;
                            }

                            inlineSection.Caption = newElement.Caption;

                            foreach (var element in inlineRoot.Sections[0].Elements)
                            {
                                inlineSection.Add(element);
                            }

                            //root.Groups.Add(inlineRoot.Groups[0]);
                        }
                        else
                        {
                            lastSection.Add(newElement);
                        }
                    }
                }
            }

            foreach (var section in sectionList)
            {
                var orderedList = section.Elements.OrderBy(e => e.Order).ToList();
                section.Elements = orderedList;
            }

            var orderedSections = sectionList.Where(s => s.Elements.Count > 0).OrderBy(section => section.Order).ToList();

            return(orderedSections);
        }
Пример #8
0
		private ISection CreateSelectCollectionSection(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			object context = view;

			var csection = new Section() { IsMultiselect = false, Opaque = false };
			var index = 0;

			SetDefaultConverter(view, member, "DataContext", new EnumerableConverter(), null, bindings);
		
			var dataContextMember = GetMemberFromDataContext(member, ref context);

			var collection = dataContextMember.GetValue(context) as IEnumerable;

			foreach (var item in collection)
			{
				var radioElement = new RadioElement(item.ToString()) { Item = item, Index = index, DataContext = false};
				
				csection.Add(radioElement);
				index++;
			}
			
			csection.ViewBinding.DataContextCode = DataContextCode.Enumerable;
			csection.ViewBinding.ViewType = null;

			return csection;
		}
Пример #9
0
		private ISection CreateEnumSection(Theme theme, MemberInfo member, IEnumerable values, object currentValue, bool popOnSelection, List<Binding> bindings)
		{
			var csection = new Section() { Opaque = false };

			int index = 0;
			int selected = -1; 

			foreach(var value in values)
			{
				if (currentValue != null && currentValue.Equals(value))
					selected = index;
				
				var description = value.ToString();
				
				if (value.GetType().IsEnum)
					description = ((Enum)value).GetDescription();
				
				var radioElement = new RadioElement(description) { Item = value };
				radioElement.Index = index;
				radioElement.PopOnSelect = popOnSelection;
				radioElement.DataContext = selected == index;
				radioElement.Opaque = false;

				csection.Add(radioElement);
				index++;
			}

			csection.ViewBinding.DataContextCode = DataContextCode.Enum;

			return csection;
		}
Пример #10
0
		public void UpdateSelected(RadioElement element, bool selected)
		{
			if (element != null)
			{
				element.DataContext = selected;
				element.UpdateSelected();
			}
		}
Пример #11
0
		public static ISection CreateEnumSection(IRoot root, IEnumerable values, object currentValue, bool popOnSelection)
		{
			var csection = new Section() { Opaque = false };

			int index = 0;
			int selected = 0;
		
			ApplyElementTheme(root.Theme, csection, null); 

			foreach(var value in values)
			{
				if (currentValue == value)
					selected = index;
				
				var description = value.ToString();

				if (value.GetType() == typeof(Enum))
					description = ((Enum)value).GetDescription(); 
				
				var radioElement = new RadioElement(description) { };
				radioElement.Index = index;
				radioElement.PopOnSelect = popOnSelection;
				radioElement.Value = selected == index;
				radioElement.Opaque = false;
				
				ApplyElementTheme(root.Theme, radioElement, null); 

				csection.Add(radioElement);
				index++;
			}

			csection.Parent = root as IElement;

			return csection;
		}
Пример #12
0
		private List<ISection> CreateSectionList(object view, IRoot root)
		{
			var memberFuncMap = new List<Func<object, MemberInfo[]>>() 
			{
				(T)=>GetFields(T),
				(T)=>GetProperties(T),
				(T)=>GetMethods(T)
			};

			ISection lastSection = new Section() { Order = -1, Parent = root as IElement };

			var sectionList = new List<ISection>() { lastSection };

			IElement newElement = null;
			Theme theme = null;
			var themeable = root as IThemeable;
			if (themeable != null)
			{
				ApplyRootTheme(view, themeable);
				theme = themeable.Theme;
				ApplyElementTheme(theme, lastSection, null);
			}

			foreach(var memberFunc in memberFuncMap)
			{
				var members = memberFunc(view);
	
				foreach (var member in members)
				{
					var pullToRefreshAttribute = member.GetCustomAttribute<PullToRefreshAttribute>();
					if (pullToRefreshAttribute != null)
					{
						root.PullToRefreshCommand = GetCommandForMember(view, member);
						root.DefaultSettingsKey = pullToRefreshAttribute.SettingsKey;
					}
					var skipAttribute = member.GetCustomAttribute<SkipAttribute>(true);
					if (skipAttribute != null) continue;
					
					var inline = member.GetCustomAttribute<InlineAttribute>() != null;
				//	var isRoot = member.GetCustomAttribute<RootAttribute>() != null;
					var listAttribute = member.GetCustomAttribute<ListAttribute>();		
					var isList = listAttribute != null;
					var sectionAttribute = member.GetCustomAttribute<SectionAttribute>();
	
					if (sectionAttribute != null)
					{	
						Theme sectionTheme = null;
						if (sectionAttribute.ThemeType != null)
							 sectionTheme = Activator.CreateInstance(sectionAttribute.ThemeType) as Theme;
						
						lastSection = new Section(sectionAttribute.Caption, sectionAttribute.Footer) { Order = sectionAttribute.Order };
						lastSection.Parent = root as IElement;
						ApplyElementTheme(root.Theme, lastSection, null); 

						ApplyElementTheme(sectionTheme, lastSection, null);
						sectionList.Add(lastSection);
					}
	
					newElement = GetElementForMember(view, member);
					
					if(newElement != null)
					{
						newElement.Theme.MergeTheme(root.Theme);
						ApplyElementTheme(root.Theme, newElement, member);

						//var context = newElement as IView;
					//	var displayInline = (inline || !isRoot) && newElement is IRoot; //&& context != null;
						
						if (isList)
						{
							var newRoot = newElement as IRoot;
							Type viewType = newRoot.ViewBinding.ViewType ?? listAttribute.ViewType;

							string caption = null;
							if (!(view is IDataTemplate))
								caption = newElement.Caption;

							lastSection = new Section(caption,null) { };
							lastSection.Parent = root as IElement;
							ApplyElementTheme(root.Theme, lastSection, null); 
							sectionList.Add(lastSection);
			
							IEnumerable datacontext = null;
							if (view is IDataTemplate)
								datacontext = ((IDataTemplate)view).Items;
							else 
								datacontext = (IEnumerable)GetValue(member, view);

							foreach (var e in datacontext)
							{
								IElement element = null;

								if (e is IViewModel)
								{
									element = new RootElement(e.ToString());
									element.ViewBinding.ViewType = viewType;
									element.ViewBinding.DataContext = e;
									
									((IRoot)element).Theme = Theme.CreateTheme(root.Theme); 
									element.Theme = ((IRoot)element).Theme; 

									if (listAttribute.ThemeType != null)
									{
										var listTheme = Activator.CreateInstance(listAttribute.ThemeType) as Theme;
										var rootTheme = Theme.CreateTheme(((IRoot)element).Theme);
										rootTheme.MergeTheme(listTheme);
										((IRoot)element).Theme = rootTheme;
									}
								}
								else
								{
									element = new RadioElement(e.ToString());
									element.Theme = ((IRoot)element).Theme; 
									
								}
		
								lastSection.Add(element);
							}

						}
						else if (inline)
						{	
							var inlineSection = new Section(string.Empty, null) {  };
							ApplyElementTheme(newElement.Theme, inlineSection, null);
							inlineSection.Parent = root as IElement;
							sectionList.Add(inlineSection);
	
							IRoot inlineRoot = newElement as IRoot;
							if (newElement.ViewBinding.DataContextCode == DataContextCode.Object)
							{
								var bindingContext = new BindingContext(newElement.ViewBinding.CurrentView, newElement.Caption, newElement.Theme);
								inlineRoot = bindingContext.Root;
							}

							inlineSection.Caption = newElement.Caption;
	
							foreach(var element in inlineRoot.Sections[0].Elements)
								inlineSection.Add(element);

							//root.Groups.Add(inlineRoot.Groups[0]);
						}
						else
						{
							lastSection.Add(newElement);
						}
					}
				}
			}
			
			foreach (var section in sectionList)
			{
				var orderedList = section.Elements.OrderBy(e=>e.Order).ToList();
				section.Elements = orderedList;
			}

			var orderedSections = sectionList.Where(s=>s.Elements.Count > 0).OrderBy(section=>section.Order).ToList();
			return orderedSections;
		}