Example #1
0
        private IElement CreateFloatElement(MemberInfo member, string caption, object view, List <Binding> 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, DataContext = rangeAttribute.Low
                };
                element = floatElement;
            }
            else
            {
                var    entryAttribute = member.GetCustomAttribute <EntryAttribute>();
                string placeholder    = null;
                var    keyboardType   = UIKeyboardType.DecimalPad;

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

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

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

            return(element);
        }
Example #2
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()
                });
            });
        }
		private IElement CreateFloatElement(MemberInfo member, string caption, object view, List<Binding> 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, DataContext = rangeAttribute.Low };
				element = floatElement;
			}
			else 
			{		
				var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
				string placeholder = null;
				var keyboardType = UIKeyboardType.DecimalPad;

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

				element = new EntryElement(caption) { Placeholder = placeholder, KeyboardType = keyboardType};
			}
		
			SetDefaultConverter(view, member, "DataContext", new FloatConverter(), null, bindings);

			return element;
		}
Example #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() };
			});
		}