Exemple #1
0
        private void BuildElementPropertyMap()
        {
            _ElementPropertyMap = new Dictionary <Type, Func <MemberInfo, string, object, List <Binding>, Element> >();
            _ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, dataContext, bindings) =>
            {
                Element element = null;

                var buttonAttribute = member.GetCustomAttribute <ButtonAttribute>();
                if (buttonAttribute != null)
                {
                    element = new ButtonElement(caption)
                    {
                        BackgroundColor = buttonAttribute.BackgroundColor,
                        TextColor       = buttonAttribute.TextColor,
                        Command         = GetCommandForMember(dataContext, member)
                    };
                }

                return(element);
            });

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

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

                return(element);
            });

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

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

                if (passwordAttribute != null)
                {
                    element = new EntryElement(caption, passwordAttribute.Placeholder, true);
                }
                else if (entryAttribute != null)
                {
                    element = new EntryElement(caption, entryAttribute.Placeholder)
                    {
                        KeyboardType = entryAttribute.KeyboardType
                    }
                }
                ;
                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, dataContext));

                    if (alignmentAttribute != null)
                    {
                        selement.Alignment = alignmentAttribute.Alignment;
                    }

                    element = selement;
                }

                var tappable = element as ITappable;
                if (tappable != null)
                {
                    ((ITappable)element).Command = GetCommandForMember(dataContext, member);
                }

                return(element);
            });

            _ElementPropertyMap.Add(typeof(float), (member, caption, dataContext, bindings) =>
            {
                Element element    = null;
                var rangeAttribute = member.GetCustomAttribute <RangeAttribute>();
                if (rangeAttribute != null)
                {
                    var floatElement = new FloatElement()
                    {
                    };
                    floatElement.Caption = caption;
                    element = floatElement;

                    floatElement.MinValue    = rangeAttribute.Low;
                    floatElement.MaxValue    = rangeAttribute.High;
                    floatElement.ShowCaption = rangeAttribute.ShowCaption;
                }
                else
                {
                    var entryAttribute = member.GetCustomAttribute <EntryAttribute>();
                    var placeholder    = "";
                    var keyboardType   = UIKeyboardType.NumberPad;

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

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

                return(element);
            });

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

            _ElementPropertyMap.Add(typeof(bool), (member, caption, dataContext, bindings) =>
            {
                Element 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, dataContext, bindings) =>
            {
                Element element = null;

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

                if (dateAttribute != null)
                {
                    element = new DateElement(caption);
                }
                else if (timeAttribute != null)
                {
                    element = new TimeElement(caption);
                }
                else
                {
                    element = new DateTimeElement(caption);
                }

                return(element);
            });

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

            _ElementPropertyMap.Add(typeof(int), (member, caption, dataContext, bindings) =>
            {
                return(new StringElement(caption)
                {
                    Value = GetValue(member, dataContext).ToString()
                });
            });
        }
		private void BuildElementPropertyMap()
		{
			_ElementPropertyMap = new Dictionary<Type, Func<MemberInfo, string, object, List<Binding>, Element>>();
			_ElementPropertyMap.Add(typeof(MethodInfo), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
	
				var buttonAttribute = member.GetCustomAttribute<ButtonAttribute>();
				if (buttonAttribute != null)
				{	
					element = new ButtonElement(caption)
					{
						BackgroundColor = buttonAttribute.BackgroundColor,
						TextColor = buttonAttribute.TextColor,
						Command = GetCommandForMember(dataContext, member)
					};
				}

				return element;
			});

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

				return element;
			});

			_ElementPropertyMap.Add(typeof(string), (member, caption, dataContext, bindings)=>
			{
				Element element = null;
	
				var passwordAttribute = member.GetCustomAttribute<PasswordAttribute>();
				var entryAttribute = member.GetCustomAttribute<EntryAttribute>();
				var multilineAttribute = member.GetCustomAttribute<MultilineAttribute>();
				var htmlAttribute = member.GetCustomAttribute<HtmlAttribute>();
				var alignmentAttribute = member.GetCustomAttribute<AlignmentAttribute>();
		
				if (passwordAttribute != null)
					element = new EntryElement(caption, passwordAttribute.Placeholder, true);
				else if (entryAttribute != null)
					element = new EntryElement(caption, entryAttribute.Placeholder) { KeyboardType = entryAttribute.KeyboardType };
				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, dataContext));
					
					if (alignmentAttribute != null)
						selement.Alignment = alignmentAttribute.Alignment;
					
					element = selement;
				}

				var tappable = element as ITappable;
				if (tappable != null)
					((ITappable)element).Command = GetCommandForMember(dataContext, member);
				
				return element;
			});

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

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

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

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

			_ElementPropertyMap.Add(typeof(bool), (member, caption, dataContext, bindings)=>
			{
				Element 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, dataContext, bindings)=>
			{
				Element element = null;

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

				if(dateAttribute != null)
					element = new DateElement(caption);
				else if (timeAttribute != null)
					element = new TimeElement(caption);
				else
					element = new DateTimeElement(caption);
				
				return element;
			});

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

			_ElementPropertyMap.Add(typeof(int), (member, caption, dataContext, bindings)=>
			{
				return new StringElement(caption) { Value = GetValue(member, dataContext).ToString() };
			});
		}