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

            var csection = new Section()
            {
                IsMultiselect = true, 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 checkboxElement = new CheckboxElement(item.ToString())
                {
                    Item = item, Index = index, DataContext = false
                };

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

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

            return(csection);
        }
Пример #2
0
        private ISection CreateEnumCollectionSection(MemberInfo member, string caption, object view, List <Binding> bindings)
        {
            Type memberType = GetTypeForMember(member);

            object context     = view;
            var    dataContext = view as IDataContext;

            if (dataContext != null)
            {
                context = dataContext.DataContext;
            }

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

            member = GetMemberFromDataContext(member, ref context);

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

            var collection = member.GetValue(view);

            if (collection == null)
            {
                var    collectionType = typeof(EnumCollection <>);
                var    enumType       = memberType.GetGenericArguments().FirstOrDefault();
                Type[] generic        = { enumType };

                collection = Activator.CreateInstance(collectionType.MakeGenericType(generic));
                member.SetValue(view, collection);
            }

            var index = 0;
            var items = (EnumCollection)collection;

            foreach (var item in items.Items)
            {
                var checkboxElement = new CheckboxElement(item.Description)
                {
                    Item        = item,
                    Index       = index,
                    DataContext = item.IsChecked,
                    Group       = item.GroupName
                };

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

            csection.DataContext = memberType;
            csection.ViewBinding.DataContextCode = DataContextCode.EnumCollection;

            return(csection);
        }
Пример #3
0
        public IElement CreateEnumCollectionRoot(MemberInfo member, string caption, object view, List <Binding> bindings)
        {
            Type memberType = GetTypeForMember(member);

            SetDefaultConverter(member, "Value", new EnumItemsConverter(), bindings);

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

            ApplyRootTheme(view, csection);

            var collection = GetValue(member, view);

            if (collection == null)
            {
                var    collectionType = typeof(EnumCollection <>);
                var    enumType       = memberType.GetGenericArguments()[0];
                Type[] generic        = { enumType };

                collection = Activator.CreateInstance(collectionType.MakeGenericType(generic));
                (member as PropertyInfo).SetValue(view, collection, new object[] {});
            }

            var index = 0;
            var items = (EnumCollection)collection;

            foreach (var item in items.AllValues)
            {
                var checkboxElement = new CheckboxElement(item.Description)
                {
                    Index = index, Value = item.IsChecked, Group = item.GroupName
                };
                ApplyRootTheme(view, checkboxElement);

                csection.Add(checkboxElement);

                index++;
            }

            var element = new RootElement(caption)
            {
                csection
            };

            element.ViewBinding.DataContextCode = DataContextCode.EnumCollection;

            element.Theme.CellStyle = UITableViewCellStyle.Value1;

            return(element);
        }
Пример #4
0
        private void BuildElementPropertyMap()
        {
            _ElementPropertyMap = new Dictionary <Type, Func <MemberInfo, string, object, List <Binding>, IElement> >();
            _ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var buttonAttribute = member.GetCustomAttribute <ButtonAttribute>();
                if (buttonAttribute != null)
                {
                    var belement = new ButtonElement(caption)
                    {
                        Command = GetCommandForMember(view, member)
                    };

                    ((ReflectiveCommand)belement.Command).Element = belement;

                    belement.Command.CanExecuteChanged += HandleCanExecuteChanged;
                    element = belement;
                }

                var loadMoreAttribute = member.GetCustomAttribute <LoadMoreAttribute>();
                if (loadMoreAttribute != null)
                {
                    var normalCaption  = !string.IsNullOrEmpty(loadMoreAttribute.NormalCaption) ? loadMoreAttribute.NormalCaption: "Load More";
                    var loadingCaption = !string.IsNullOrEmpty(loadMoreAttribute.LoadingCaption) ? loadMoreAttribute.LoadingCaption: "Loading...";

                    element = new LoadMoreElement(normalCaption, loadingCaption, null)
                    {
                        Command = GetCommandForMember(view, member)
                    };
                }

                var enableSearchAttribute = member.GetCustomAttribute <EnableSearchAttribute>();
                var searchbar             = Root as ISearchBar;
                if (enableSearchAttribute != null && searchbar != null)
                {
                    searchbar.AutoHideSearch    = enableSearchAttribute.AutoHide;
                    searchbar.SearchPlaceholder = enableSearchAttribute.Placeholder;
                    searchbar.IncrementalSearch = enableSearchAttribute.IncrementalSearch;
                    searchbar.EnableSearch      = true;

                    var methodInfo          = member as MethodInfo;
                    searchbar.SearchCommand = new SearchCommand(view, methodInfo);
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var mapAttribute = member.GetCustomAttribute <MapAttribute>();
                var location     = (CLLocationCoordinate2D)GetValue(member, view);
                if (mapAttribute != null)
                {
                    element = new MapElement(mapAttribute.Caption, location);
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(string), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var passwordAttribute  = member.GetCustomAttribute <PasswordAttribute>();
                var entryAttribute     = member.GetCustomAttribute <EntryAttribute>();
                var multilineAttribute = member.GetCustomAttribute <MultilineAttribute>();
                var htmlAttribute      = member.GetCustomAttribute <HtmlAttribute>();

                if (passwordAttribute != null)
                {
                    element = new EntryElement(caption)
                    {
                        Placeholder = passwordAttribute.Placeholder, KeyboardType = passwordAttribute.KeyboardType, IsPassword = true, EditMode = entryAttribute.EditMode, AutoCorrectionType = passwordAttribute.AutoCorrectionType, AutoCapitalizationType = passwordAttribute.AutoCapitalizationType
                    };
                }
                else if (entryAttribute != null)
                {
                    element = new EntryElement(caption)
                    {
                        Placeholder = entryAttribute.Placeholder, KeyboardType = entryAttribute.KeyboardType, EditMode = entryAttribute.EditMode, AutoCorrectionType = entryAttribute.AutoCorrectionType, AutoCapitalizationType = entryAttribute.AutoCapitalizationType
                    };
                }
                else if (multilineAttribute != null)
                {
                    element = new MultilineElement(caption);
                }
                else if (htmlAttribute != null)
                {
                    SetDefaultConverter(member, "Value", new UriConverter(), bindings);
                    element = new HtmlElement(caption);
                }
                else
                {
                    var selement = new StringElement(caption, (string)GetValue(member, view))
                    {
                    };

                    element = selement;
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(float), (member, caption, view, bindings) =>
            {
                IElement element   = null;
                var rangeAttribute = member.GetCustomAttribute <RangeAttribute>();
                if (rangeAttribute != null)
                {
                    var floatElement = new FloatElement(caption)
                    {
                        ShowCaption = rangeAttribute.ShowCaption, MinValue = rangeAttribute.Low, MaxValue = rangeAttribute.High, Value = rangeAttribute.Low
                    };
                    element = floatElement;
                }
                else
                {
                    var entryAttribute = member.GetCustomAttribute <EntryAttribute>();
                    string placeholder = null;
                    var keyboardType   = UIKeyboardType.NumberPad;

                    if (entryAttribute != null)
                    {
                        placeholder = entryAttribute.Placeholder;
                        if (entryAttribute.KeyboardType != UIKeyboardType.Default)
                        {
                            keyboardType = entryAttribute.KeyboardType;
                        }
                    }

                    element = new EntryElement(caption)
                    {
                        Placeholder = placeholder, KeyboardType = keyboardType
                    };
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(Uri), (member, caption, view, bindings) =>
            {
                return(new HtmlElement(caption, (Uri)GetValue(member, view)));
            });

            _ElementPropertyMap.Add(typeof(bool), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var checkboxAttribute = member.GetCustomAttribute <CheckboxAttribute>();
                if (checkboxAttribute != null)
                {
                    element = new CheckboxElement(caption)
                    {
                    }
                }
                ;
                else
                {
                    element = new BooleanElement(caption)
                    {
                    }
                };

                return(element);
            });

            _ElementPropertyMap.Add(typeof(DateTime), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var dateAttribute = member.GetCustomAttribute <DateAttribute>();
                var timeAttribute = member.GetCustomAttribute <TimeAttribute>();

                if (dateAttribute != null)
                {
                    element = new DateElement(caption)
                    {
                        Value = (DateTime)GetValue(member, view)
                    }
                }
                ;
                else if (timeAttribute != null)
                {
                    element = new TimeElement(caption)
                    {
                        Value = (DateTime)GetValue(member, view)
                    }
                }
                ;
                else
                {
                    element = new DateTimeElement(caption)
                    {
                        Value = (DateTime)GetValue(member, view)
                    }
                };

                return(element);
            });

            _ElementPropertyMap.Add(typeof(UIImage), (member, caption, view, bindings) =>
            {
                return(new ImageElement());
            });

            _ElementPropertyMap.Add(typeof(int), (member, caption, view, bindings) =>
            {
                SetDefaultConverter(member, "Value", new IntConverter(), bindings);
                return(new StringElement(caption)
                {
                    Value = GetValue(member, view).ToString()
                });
            });
        }
Пример #5
0
		private void BuildElementPropertyMap()
		{
			_ElementPropertyMap = new Dictionary<Type, Func<MemberInfo, string, object, List<Binding>, IElement>>();
			_ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, view, bindings)=>
			{
				IElement element = null;
				
				var loadMoreAttribute = member.GetCustomAttribute<LoadMoreAttribute>();
				if (loadMoreAttribute != null)
				{
					var normalCaption = !string.IsNullOrEmpty(loadMoreAttribute.NormalCaption) ? loadMoreAttribute.NormalCaption: "Load More";
					var loadingCaption =  !string.IsNullOrEmpty(loadMoreAttribute.LoadingCaption) ? loadMoreAttribute.LoadingCaption: "Loading...";

					element = new LoadMoreElement(normalCaption, loadingCaption, null) { Command = GetCommandForMember(view, member) };
				}

				var searchbarAttribute = member.GetCustomAttribute<SearchbarAttribute>();
				var searchbar = Root as ISearchBar;
				if (searchbarAttribute != null && searchbar != null)
				{
					searchbar.SearchPlaceholder = searchbarAttribute.Placeholder;
					searchbar.IncrementalSearch = searchbarAttribute.IncrementalSearch;
					searchbar.EnableSearch = true;
					searchbar.IsSearchbarHidden = false;
					
					var methodInfo = member as MethodInfo;
					searchbar.SearchCommand = new SearchCommand(view, methodInfo);
				}
				
				var buttonAttribute = member.GetCustomAttribute<ButtonAttribute>();
				if (buttonAttribute != null)
				{	
					var belement = new ButtonElement(caption)
					{
						Command = GetCommandForMember(view, member)
					};
					
					((ReflectiveCommand)belement.Command).Element = belement;

					belement.Command.CanExecuteChanged += HandleCanExecuteChanged;
					element = belement;
				}

				return element ?? _NoElement;
			});
			
			_ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, view, bindings)=>
			{
				IElement element = null;
		
				var mapAttribute = member.GetCustomAttribute<MapAttribute>();
				var location = (CLLocationCoordinate2D)member.GetValue(view);
				if (mapAttribute != null)
					element = new MapElement(mapAttribute.Caption, location);

				return element;
			});

			_ElementPropertyMap.Add(typeof(string), (member, caption, view, bindings)=>
			{
				IElement element = null;
	
				var passwordAttribute = member.GetCustomAttribute<PasswordAttribute>();
				var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
				var multilineAttribute = member.GetCustomAttribute<MultilineAttribute>();
				var htmlAttribute = member.GetCustomAttribute<HtmlAttribute>();
		
				if (passwordAttribute != null)
				{
					element = new EntryElement(caption) { Placeholder = passwordAttribute.Placeholder, KeyboardType = passwordAttribute.KeyboardType, IsPassword = true, EditMode = entryAttribute.EditMode, AutoCorrectionType = passwordAttribute.AutoCorrectionType, AutoCapitalizationType = passwordAttribute.AutoCapitalizationType };
				} 
				else if (entryAttribute != null)
				{
					element = new EntryElement(caption) { Placeholder = entryAttribute.Placeholder, KeyboardType = entryAttribute.KeyboardType, EditMode = entryAttribute.EditMode,  AutoCorrectionType = entryAttribute.AutoCorrectionType, AutoCapitalizationType = entryAttribute.AutoCapitalizationType };
				}
				else if (multilineAttribute != null)
					element = new MultilineElement(caption);
				else if (htmlAttribute != null)
				{
					SetDefaultConverter(view, member, "DataContext", new UriConverter(), null, bindings);
					element = new HtmlElement(caption);
				}
				else
				{
					var selement = new StringElement(caption, (string)member.GetValue(view)) { };
					
					element = selement;
				}
				
				return element;
			});

			_ElementPropertyMap.Add(typeof(Single), (member, caption, view, bindings)=>
			{
				return CreateFloatElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(Double), (member, caption, view, bindings)=>
			{
				return CreateFloatElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(Uri), (member, caption, view, bindings)=>
			{
				return new HtmlElement(caption, (Uri)member.GetValue(view));  
			});

			_ElementPropertyMap.Add(typeof(bool), (member, caption, view, bindings)=>
			{
				IElement element = null;

				var checkmarkAttribute = member.GetCustomAttribute<CheckmarkAttribute>();
				if (checkmarkAttribute != null)
				    element = new CheckboxElement(caption) {  };
				else
					element = new BooleanElement(caption) { };

				return element;
			});

			_ElementPropertyMap.Add(typeof(DateTime), (member, caption, view, bindings)=>
			{
				IElement element = null;

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

				var dateAttribute = member.GetCustomAttribute<DateAttribute>();
				var timeAttribute = member.GetCustomAttribute<TimeAttribute>();

				if(dateAttribute != null)
					element = new DateElement(caption) { DataContext = (DateTime)member.GetValue(view)};
				else if (timeAttribute != null)
					element = new TimeElement(caption) { DataContext = (DateTime)member.GetValue(view)};
				else
					element = new DateTimeElement(caption) { DataContext = (DateTime)member.GetValue(view)};
				
				return element;
			});

			_ElementPropertyMap.Add(typeof(UIImage),(member, caption, view, bindings)=>
			{
				return new ImageElement((UIImage)member.GetValue(view));
			});

			_ElementPropertyMap.Add(typeof(Int32), (member, caption, view, bindings)=>
			{				
				return CreateIntElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(Int16), (member, caption, view, bindings)=>
			{				
				return CreateIntElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(Int64), (member, caption, view, bindings)=>
			{				
				return CreateIntElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(UInt32), (member, caption, view, bindings)=>
			{				
				return CreateIntElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(UInt16), (member, caption, view, bindings)=>
			{				
				return CreateIntElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(UInt64), (member, caption, view, bindings)=>
			{				
				return CreateIntElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(Byte), (member, caption, view, bindings)=>
			{				
				return CreateIntElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(SByte), (member, caption, view, bindings)=>
			{				
				return CreateIntElement(member, caption, view, bindings);
			});

			_ElementPropertyMap.Add(typeof(Decimal), (member, caption, view, bindings)=>
			{				
				return CreateFloatElement(member, caption, view, bindings);
			});
		}
Пример #6
0
		private ISection CreateMultiselectCollectionSection(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			object context = view;

			var csection = new Section() { IsMultiselect = true, 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 checkboxElement = new CheckboxElement(item.ToString()) { Item = item, Index = index, DataContext = false};
				
				csection.Add(checkboxElement);
				index++;
			}
			
			csection.ViewBinding.DataContextCode = DataContextCode.MultiselectCollection;
			csection.ViewBinding.ViewType = null;

			return csection;
		}
Пример #7
0
		private ISection CreateEnumCollectionSection(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			Type memberType = GetTypeForMember(member);
			
			object context = view;
			var dataContext = view as IDataContext;

			if (dataContext != null)
			{
				context = dataContext.DataContext;
			}
			
			SetDefaultConverter(view, member, "DataContext", new EnumCollectionConverter(), null, bindings);

			member = GetMemberFromDataContext(member, ref context);

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

			var collection = member.GetValue(view);
			if (collection == null)
			{
				var collectionType = typeof(EnumCollection<>);
				var enumType = memberType.GetGenericArguments().FirstOrDefault();
				Type[] generic = { enumType };

				collection = Activator.CreateInstance(collectionType.MakeGenericType(generic));
				member.SetValue(view, collection);
			}

			var index = 0;
			var items = (EnumCollection)collection;
			foreach (var item in items.Items)
			{
				var checkboxElement = new CheckboxElement(item.Description) 
				{ 
					Item = item, 
					Index = index, 
					DataContext = item.IsChecked, 
					Group = item.GroupName
				};

				csection.Add(checkboxElement);				
				index++;
			}
			
			csection.DataContext = memberType;
			csection.ViewBinding.DataContextCode = DataContextCode.EnumCollection;

			return csection;
		}
Пример #8
0
        private void BuildElementPropertyMap()
        {
            _ElementPropertyMap = new Dictionary <Type, Func <MemberInfo, string, object, List <Binding>, IElement> >();
            _ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var loadMoreAttribute = member.GetCustomAttribute <LoadMoreAttribute>();
                if (loadMoreAttribute != null)
                {
                    var normalCaption  = !string.IsNullOrEmpty(loadMoreAttribute.NormalCaption) ? loadMoreAttribute.NormalCaption: "Load More";
                    var loadingCaption = !string.IsNullOrEmpty(loadMoreAttribute.LoadingCaption) ? loadMoreAttribute.LoadingCaption: "Loading...";

                    element = new LoadMoreElement(normalCaption, loadingCaption, null)
                    {
                        Command = GetCommandForMember(view, member)
                    };
                }

                var searchbarAttribute = member.GetCustomAttribute <SearchbarAttribute>();
                var searchbar          = Root as ISearchBar;
                if (searchbarAttribute != null && searchbar != null)
                {
                    searchbar.SearchPlaceholder = searchbarAttribute.Placeholder;
                    searchbar.IncrementalSearch = searchbarAttribute.IncrementalSearch;
                    searchbar.EnableSearch      = true;
                    searchbar.IsSearchbarHidden = false;

                    var methodInfo          = member as MethodInfo;
                    searchbar.SearchCommand = new SearchCommand(view, methodInfo);
                }

                var buttonAttribute = member.GetCustomAttribute <ButtonAttribute>();
                if (buttonAttribute != null)
                {
                    var belement = new ButtonElement(caption)
                    {
                        Command = GetCommandForMember(view, member)
                    };

                    ((ReflectiveCommand)belement.Command).Element = belement;

                    belement.Command.CanExecuteChanged += HandleCanExecuteChanged;
                    element = belement;
                }

                return(element ?? _NoElement);
            });

            _ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var mapAttribute = member.GetCustomAttribute <MapAttribute>();
                var location     = (CLLocationCoordinate2D)member.GetValue(view);
                if (mapAttribute != null)
                {
                    element = new MapElement(mapAttribute.Caption, location);
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(string), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var passwordAttribute  = member.GetCustomAttribute <PasswordAttribute>();
                var entryAttribute     = member.GetCustomAttribute <EntryAttribute>();
                var multilineAttribute = member.GetCustomAttribute <MultilineAttribute>();
                var htmlAttribute      = member.GetCustomAttribute <HtmlAttribute>();

                if (passwordAttribute != null)
                {
                    element = new EntryElement(caption)
                    {
                        Placeholder = passwordAttribute.Placeholder, KeyboardType = passwordAttribute.KeyboardType, IsPassword = true, EditMode = entryAttribute.EditMode, AutoCorrectionType = passwordAttribute.AutoCorrectionType, AutoCapitalizationType = passwordAttribute.AutoCapitalizationType
                    };
                }
                else if (entryAttribute != null)
                {
                    element = new EntryElement(caption)
                    {
                        Placeholder = entryAttribute.Placeholder, KeyboardType = entryAttribute.KeyboardType, EditMode = entryAttribute.EditMode, AutoCorrectionType = entryAttribute.AutoCorrectionType, AutoCapitalizationType = entryAttribute.AutoCapitalizationType
                    };
                }
                else if (multilineAttribute != null)
                {
                    element = new MultilineElement(caption);
                }
                else if (htmlAttribute != null)
                {
                    SetDefaultConverter(view, member, "DataContext", new UriConverter(), null, bindings);
                    element = new HtmlElement(caption);
                }
                else
                {
                    var selement = new StringElement(caption, (string)member.GetValue(view))
                    {
                    };

                    element = selement;
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(Single), (member, caption, view, bindings) =>
            {
                return(CreateFloatElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(Double), (member, caption, view, bindings) =>
            {
                return(CreateFloatElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(Uri), (member, caption, view, bindings) =>
            {
                return(new HtmlElement(caption, (Uri)member.GetValue(view)));
            });

            _ElementPropertyMap.Add(typeof(bool), (member, caption, view, bindings) =>
            {
                IElement element = null;

                var checkmarkAttribute = member.GetCustomAttribute <CheckmarkAttribute>();
                if (checkmarkAttribute != null)
                {
                    element = new CheckboxElement(caption)
                    {
                    }
                }
                ;
                else
                {
                    element = new BooleanElement(caption)
                    {
                    }
                };

                return(element);
            });

            _ElementPropertyMap.Add(typeof(DateTime), (member, caption, view, bindings) =>
            {
                IElement element = null;

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

                var dateAttribute = member.GetCustomAttribute <DateAttribute>();
                var timeAttribute = member.GetCustomAttribute <TimeAttribute>();

                if (dateAttribute != null)
                {
                    element = new DateElement(caption)
                    {
                        DataContext = (DateTime)member.GetValue(view)
                    }
                }
                ;
                else if (timeAttribute != null)
                {
                    element = new TimeElement(caption)
                    {
                        DataContext = (DateTime)member.GetValue(view)
                    }
                }
                ;
                else
                {
                    element = new DateTimeElement(caption)
                    {
                        DataContext = (DateTime)member.GetValue(view)
                    }
                };

                return(element);
            });

            _ElementPropertyMap.Add(typeof(UIImage), (member, caption, view, bindings) =>
            {
                return(new ImageElement((UIImage)member.GetValue(view)));
            });

            _ElementPropertyMap.Add(typeof(Int32), (member, caption, view, bindings) =>
            {
                return(CreateIntElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(Int16), (member, caption, view, bindings) =>
            {
                return(CreateIntElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(Int64), (member, caption, view, bindings) =>
            {
                return(CreateIntElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(UInt32), (member, caption, view, bindings) =>
            {
                return(CreateIntElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(UInt16), (member, caption, view, bindings) =>
            {
                return(CreateIntElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(UInt64), (member, caption, view, bindings) =>
            {
                return(CreateIntElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(Byte), (member, caption, view, bindings) =>
            {
                return(CreateIntElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(SByte), (member, caption, view, bindings) =>
            {
                return(CreateIntElement(member, caption, view, bindings));
            });

            _ElementPropertyMap.Add(typeof(Decimal), (member, caption, view, bindings) =>
            {
                return(CreateFloatElement(member, caption, view, bindings));
            });
        }
Пример #9
0
		private void BuildElementPropertyMap()
		{
			_ElementPropertyMap = new Dictionary<Type, Func<MemberInfo, string, object, List<Binding>, IElement>>();
			_ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, view, bindings)=>
			{
				IElement element = null;
	
				var buttonAttribute = member.GetCustomAttribute<ButtonAttribute>();
				if (buttonAttribute != null)
				{	
					var belement = new ButtonElement(caption)
					{
						Command = GetCommandForMember(view, member)
					};
					
					((ReflectiveCommand)belement.Command).Element = belement;

					belement.Command.CanExecuteChanged += HandleCanExecuteChanged;
					element = belement;
				}
				
				var loadMoreAttribute = member.GetCustomAttribute<LoadMoreAttribute>();
				if (loadMoreAttribute != null)
				{
					var normalCaption = !string.IsNullOrEmpty(loadMoreAttribute.NormalCaption) ? loadMoreAttribute.NormalCaption: "Load More";
					var loadingCaption =  !string.IsNullOrEmpty(loadMoreAttribute.LoadingCaption) ? loadMoreAttribute.LoadingCaption: "Loading...";

					element = new LoadMoreElement(normalCaption, loadingCaption, null) { Command = GetCommandForMember(view, member) };
				}

				var enableSearchAttribute = member.GetCustomAttribute<EnableSearchAttribute>();
				var searchbar = Root as ISearchBar;
				if (enableSearchAttribute != null && searchbar != null)
				{
					searchbar.AutoHideSearch = enableSearchAttribute.AutoHide;
					searchbar.SearchPlaceholder = enableSearchAttribute.Placeholder;
					searchbar.IncrementalSearch = enableSearchAttribute.IncrementalSearch;
					searchbar.EnableSearch = true;
					
					var methodInfo = member as MethodInfo;
					searchbar.SearchCommand = new SearchCommand(view, methodInfo);
				}

				return element;
			});

			_ElementPropertyMap.Add(typeof(CLLocationCoordinate2D), (member, caption, view, bindings)=>
			{
				IElement element = null;
		
				var mapAttribute = member.GetCustomAttribute<MapAttribute>();
				var location = (CLLocationCoordinate2D)GetValue(member, view);
				if (mapAttribute != null)
					element = new MapElement(mapAttribute.Caption, location);

				return element;
			});

			_ElementPropertyMap.Add(typeof(string), (member, caption, view, bindings)=>
			{
				IElement element = null;
	
				var passwordAttribute = member.GetCustomAttribute<PasswordAttribute>();
				var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
				var multilineAttribute = member.GetCustomAttribute<MultilineAttribute>();
				var htmlAttribute = member.GetCustomAttribute<HtmlAttribute>();
		
				if (passwordAttribute != null)
				{
					element = new EntryElement(caption) { Placeholder = passwordAttribute.Placeholder, KeyboardType = passwordAttribute.KeyboardType, IsPassword = true, EditMode = entryAttribute.EditMode, AutoCorrectionType = passwordAttribute.AutoCorrectionType, AutoCapitalizationType = passwordAttribute.AutoCapitalizationType };
				} 
				else if (entryAttribute != null)
				{
					element = new EntryElement(caption) { Placeholder = entryAttribute.Placeholder, KeyboardType = entryAttribute.KeyboardType, EditMode = entryAttribute.EditMode,  AutoCorrectionType = entryAttribute.AutoCorrectionType, AutoCapitalizationType = entryAttribute.AutoCapitalizationType };
				}
				else if (multilineAttribute != null)
					element = new MultilineElement(caption);
				else if (htmlAttribute != null)
				{
					SetDefaultConverter(member, "Value", new UriConverter(), bindings);
					element = new HtmlElement(caption);
				}
				else
				{
					var selement = new StringElement(caption, (string)GetValue(member, view)) { };
					
					element = selement;
				}
				
				return element;
			});

			_ElementPropertyMap.Add(typeof(float), (member, caption, view, bindings)=>
			{
				IElement element = null;
				var rangeAttribute = member.GetCustomAttribute<RangeAttribute>();
				if (rangeAttribute != null)
				{
					var floatElement = new FloatElement(caption) {  ShowCaption = rangeAttribute.ShowCaption, MinValue = rangeAttribute.Low, MaxValue = rangeAttribute.High, Value = rangeAttribute.Low };
					element = floatElement;
				}
				else 
				{		
					var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
					string placeholder = null;
					var keyboardType = UIKeyboardType.NumberPad;

					if(entryAttribute != null)
					{
						placeholder = entryAttribute.Placeholder;
						if(entryAttribute.KeyboardType != UIKeyboardType.Default)
							keyboardType = entryAttribute.KeyboardType;
					}

					element = new EntryElement(caption) { Placeholder = placeholder, KeyboardType = keyboardType};
				}

				return element;
			});
			
			_ElementPropertyMap.Add(typeof(Uri), (member, caption, view, bindings)=>
			{
				return new HtmlElement(caption, (Uri)GetValue(member, view));  
			});

			_ElementPropertyMap.Add(typeof(bool), (member, caption, view, bindings)=>
			{
				IElement element = null;

				var checkboxAttribute = member.GetCustomAttribute<CheckboxAttribute>();
				if (checkboxAttribute != null)
				    element = new CheckboxElement(caption) {  };
				else
					element = new BooleanElement(caption) { };

				return element;
			});

			_ElementPropertyMap.Add(typeof(DateTime), (member, caption, view, bindings)=>
			{
				IElement element = null;

				var dateAttribute = member.GetCustomAttribute<DateAttribute>();
				var timeAttribute = member.GetCustomAttribute<TimeAttribute>();

				if(dateAttribute != null)
					element = new DateElement(caption) { Value = (DateTime)GetValue(member, view)};
				else if (timeAttribute != null)
					element = new TimeElement(caption) { Value = (DateTime)GetValue(member, view)};
				else
					element = new DateTimeElement(caption) { Value = (DateTime)GetValue(member, view)};
				
				return element;
			});

			_ElementPropertyMap.Add(typeof(UIImage),(member, caption, view, bindings)=>
			{
				return new ImageElement();
			});

			_ElementPropertyMap.Add(typeof(int), (member, caption, view, bindings)=>
			{
				SetDefaultConverter(member, "Value", new IntConverter(), bindings);
				return new StringElement(caption) { Value = GetValue(member, view).ToString() };
			});
		}
Пример #10
0
		public IElement CreateEnumCollectionRoot(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			Type memberType = GetTypeForMember(member);

			SetDefaultConverter(member, "Value", new EnumItemsConverter(), bindings);

			var csection = new Section() { IsMultiselect = true, Opaque = false };
			ApplyRootTheme(view, csection);

			var collection = GetValue(member, view);
			if (collection == null)
			{
				var collectionType = typeof(EnumCollection<>);
				var enumType = memberType.GetGenericArguments()[0];
				Type[] generic = { enumType };

				collection = Activator.CreateInstance(collectionType.MakeGenericType(generic));
				(member as PropertyInfo).SetValue(view, collection, new object[] {});
			}

			var index = 0;
			var items = (EnumCollection)collection;
			foreach (var item in items.AllValues)
			{
				var checkboxElement = new CheckboxElement(item.Description) { Index = index, Value = item.IsChecked, Group = item.GroupName};
				ApplyRootTheme(view, checkboxElement);

				csection.Add(checkboxElement);
				
				index++;
			}
			
			var element = new RootElement(caption) { csection };
			element.ViewBinding.DataContextCode = DataContextCode.EnumCollection;

			element.Theme.CellStyle = UITableViewCellStyle.Value1;

			return element;
		}