Inheritance: DateTimeElement
        public override void ViewDidLoad()
        {

            base.ViewDidLoad();
            
            // Perform any additional setup after loading the view
            var info = new RootElement("Info") {
                new Section() {
                    { eventname = new EntryElement("Event Name", "Enter the Name", null) },
                    { recipients = new EntryElement("Recipients' Names", "Enter the Recipients", null) },
                    { location = new EntryElement("Enter Location", "Enter the Location", null) }
                },

                new Section()
                {
                    { date = new DateElement("Pick the Date", DateTime.Now) },
                    { timeelement = new TimeElement("Pick the Time", DateTime.Now) },
                    { description = new EntryElement("Description", "Enter a Description", null) }
                },

                new Section()
                {
                    new RootElement("Type", category = new RadioGroup("Type of Event", 0)) {
                        new Section() {
                            new RadioElement ("Meeting", "Type of Event"),
                            new RadioElement ("Company Event", "Type of Event"),
                            new RadioElement ("Machine Maintenance", "Type of Event"),
                            new RadioElement ("Emergency", "Type of Event")
                        }
                    },
                    
                    new RootElement("Priority", priority = new RadioGroup ("priority", 0))
                    {
                        new Section()
                        {
                            new RadioElement("Low", "priority"),
                            new RadioElement("Medium", "priority"), 
                            new RadioElement("High", "priority")
                        }
                    }
                },
            };

            Root.Add(info);

            UIButton createEventBtn = UIButton.FromType(UIButtonType.RoundedRect);
            createEventBtn.SetTitle("Add Event", UIControlState.Normal);
            createEventBtn.Frame = new Rectangle(0, 0, 320, 44);
            int y = (int)((View.Frame.Size.Height - createEventBtn.Frame.Size.Height)/1.15);
            int x = ((int)(View.Frame.Size.Width - createEventBtn.Frame.Size.Width)) / 2;
            createEventBtn.Frame = new Rectangle(x, y, (int)createEventBtn.Frame.Width, (int)createEventBtn.Frame.Height);
            View.AddSubview(createEventBtn);


            createEventBtn.TouchUpInside += async (object sender, EventArgs e) =>
            {
                await createEvent(info);
            };
        }
        public override void ViewDidLoad()
        {
            //maybe i don't need this controler at all?!?!

            base.ViewDidLoad ();
            //this.TableView.Source = new DateTableViewSource ();
            var section = new Section ("New Checkpoint:");

            var nameElement = new EntryElement ("name", "Name your checkpoint", "");
            var instructions = new MultilineElement ("specify the time that you expect to complete this checkpoint, each day:");

            var targetElement = new TimeElement ("target", DateTime.Now);

            var aCell = new DatePickerCell(UIDatePickerMode.Time,DateTime.Now)
            {
                Key = "1234",
            };
            aCell.TextLabel.Text = "Date";
            aCell.RightLabelTextAlignment = UITextAlignment.Right;
            aCell.OnItemChanged += (object sender, PickerCellArgs e) => {

                var result = e.Items;
            };

            var saveButton = new StringElement ("save",
                () =>{
                    this.Parent.AddNewCheckPoint(nameElement.Value,targetElement.DateValue.TimeOfDay);
                    this.DismissModalViewController(true);
                }){Alignment=UITextAlignment.Right};

            var cancelButton = new StringElement ("cancel",
                () =>{
                    this.DismissModalViewController(true);
                }){Alignment=UITextAlignment.Right};

            section.AddAll (new Element[]{ nameElement, instructions, targetElement, saveButton,cancelButton });
            this.Root.Add (section);
        }
Example #3
0
		void Populate (object callbacks, object o, RootElement root)
		{
			MemberInfo last_radio_index = null;
			
			BindingFlags flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance;
			if (Attribute.GetCustomAttribute(o.GetType (), typeof(SkipNonPublicAttribute)) == null)
				flags |= BindingFlags.NonPublic;
			var members = o.GetType ().GetMembers (flags);

			Section section = null;
			
			foreach (var mi in members){
				Type mType = GetTypeForMember (mi);

				if (mType == null)
					continue;

				string caption = null;
				object [] attrs = mi.GetCustomAttributes (false);
				bool skip = false;
				foreach (var attr in attrs){
					if (attr is SkipAttribute)
						skip = true;
					if (attr is CaptionAttribute)
						caption = ((CaptionAttribute) attr).Caption;
					else if (attr is SectionAttribute){
						if (section != null)
							root.Add (section);
						var sa = attr as SectionAttribute;
						section = new Section (sa.Caption, sa.Footer);
					}
				}
				if (skip)
					continue;
				
				if (caption == null)
					caption = MakeCaption (mi.Name);
				
				if (section == null)
					section = new Section ();
				
				Element element = null;
				if (mType == typeof (string)){
					PasswordAttribute pa = null;
					AlignmentAttribute align = null;
					EntryAttribute ea = null;
					object html = null;
					NSAction invoke = null;
					bool multi = false;
					
					foreach (object attr in attrs){
						if (attr is PasswordAttribute)
							pa = attr as PasswordAttribute;
						else if (attr is EntryAttribute)
							ea = attr as EntryAttribute;
						else if (attr is MultilineAttribute)
							multi = true;
						else if (attr is HtmlAttribute)
							html = attr;
						else if (attr is AlignmentAttribute)
							align = attr as AlignmentAttribute;
						
						if (attr is OnTapAttribute){
							string mname = ((OnTapAttribute) attr).Method;
							
							if (callbacks == null){
								throw new Exception ("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor");
							}
							
							var method = callbacks.GetType ().GetMethod (mname);
							if (method == null)
								throw new Exception ("Did not find method " + mname);
							invoke = delegate {
								method.Invoke (method.IsStatic ? null : callbacks, new object [0]);
							};
						}
					}
					
					string value = (string) GetValue (mi, o);
					if (pa != null)
						element = new EntryElement (caption, pa.Placeholder, value, true);
					else if (ea != null)
						element = new EntryElement (caption, ea.Placeholder, value) { KeyboardType = ea.KeyboardType };
					else if (multi)
						element = new MultilineElement (caption, value);
					else if (html != null)
						element = new HtmlElement (caption, value);
					else {
						var selement = new StringElement (caption, value);
						element = selement;
						
						if (align != null)
							selement.Alignment = align.Alignment;
					}
					
					if (invoke != null)
						((StringElement) element).Tapped += invoke;
				} else if (mType == typeof (float)){
					var floatElement = new FloatElement (null, null, (float) GetValue (mi, o));
					floatElement.Caption = caption;
					element = floatElement;
					
					foreach (object attr in attrs){
						if (attr is RangeAttribute){
							var ra = attr as RangeAttribute;
							floatElement.MinValue = ra.Low;
							floatElement.MaxValue = ra.High;
							floatElement.ShowCaption = ra.ShowCaption;
						}
					}
				} else if (mType == typeof (bool)){
					bool checkbox = false;
					foreach (object attr in attrs){
						if (attr is CheckboxAttribute)
							checkbox = true;
					}
					
					if (checkbox)
						element = new CheckboxElement (caption, (bool) GetValue (mi, o));
					else
						element = new BooleanElement (caption, (bool) GetValue (mi, o));
				} else if (mType == typeof (DateTime)){
					var dateTime = (DateTime) GetValue (mi, o);
					bool asDate = false, asTime = false;
					
					foreach (object attr in attrs){
						if (attr is DateAttribute)
							asDate = true;
						else if (attr is TimeAttribute)
							asTime = true;
					}
					
					if (asDate)
						element = new DateElement (caption, dateTime);
					else if (asTime)
						element = new TimeElement (caption, dateTime);
					else
						 element = new DateTimeElement (caption, dateTime);
				} else if (mType.IsEnum){
					var csection = new Section ();
					ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null);
					int idx = 0;
					int selected = 0;
					
					foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){
						ulong v = Convert.ToUInt64 (GetValue (fi, null));
						
						if (v == evalue)
							selected = idx;
						
						csection.Add (new RadioElement (MakeCaption (fi.Name)));
						idx++;
					}
					
					element = new RootElement (caption, new RadioGroup (null, selected)) { csection };
				} else if (mType == typeof (UIImage)){
					element = new ImageElement ((UIImage) GetValue (mi, o));
				} else if (typeof (System.Collections.IEnumerable).IsAssignableFrom (mType)){
					var csection = new Section ();
					int count = 0;
					
					if (last_radio_index == null)
						throw new Exception ("IEnumerable found, but no previous int found");
					foreach (var e in (IEnumerable) GetValue (mi, o)){
						csection.Add (new RadioElement (e.ToString ()));
						count++;
					}
					int selected = (int) GetValue (last_radio_index, o);
					if (selected >= count || selected < 0)
						selected = 0;
					element = new RootElement (caption, new MemberRadioGroup (null, selected, last_radio_index)) { csection };
					last_radio_index = null;
				} else if (typeof (int) == mType){
					foreach (object attr in attrs){
						if (attr is RadioSelectionAttribute){
							last_radio_index = mi;
							break;
						}
					}
				} else {
					var nested = GetValue (mi, o);
					if (nested != null){
						var newRoot = new RootElement (caption);
						Populate (callbacks, nested, newRoot);
						element = newRoot;
					}
				}
				
				if (element == null)
					continue;
				section.Add (element);
				mappings [element] = new MemberAndInstance (mi, o);
			}
			root.Add (section);
		}
Example #4
0
        void Populate(object callbacks, object o, RootElement root)
        {
            MemberInfo last_radio_index = null;
            var        members          = o.GetType().GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public |
                                                                 BindingFlags.NonPublic | BindingFlags.Instance);

            Section section = null;

            foreach (var mi in members)
            {
                Type mType = GetTypeForMember(mi);

                if (mType == null)
                {
                    continue;
                }

                string    caption = null;
                object [] attrs   = mi.GetCustomAttributes(false);
                bool      skip    = false;
                foreach (var attr in attrs)
                {
                    if (attr is SkipAttribute || attr is System.Runtime.CompilerServices.CompilerGeneratedAttribute)
                    {
                        skip = true;
                    }
                    else if (attr is CaptionAttribute)
                    {
                        caption = ((CaptionAttribute)attr).Caption;
                    }
                    else if (attr is SectionAttribute)
                    {
                        if (section != null)
                        {
                            root.Add(section);
                        }
                        var sa = attr as SectionAttribute;
                        section = new Section(sa.Caption, sa.Footer);
                    }
                }
                if (skip)
                {
                    continue;
                }

                if (caption == null)
                {
                    caption = MakeCaption(mi.Name);
                }

                if (section == null)
                {
                    section = new Section();
                }

                Element element = null;
                if (mType == typeof(string))
                {
                    PasswordAttribute  pa     = null;
                    AlignmentAttribute align  = null;
                    EntryAttribute     ea     = null;
                    object             html   = null;
                    NSAction           invoke = null;
                    bool multi = false;

                    foreach (object attr in attrs)
                    {
                        if (attr is PasswordAttribute)
                        {
                            pa = attr as PasswordAttribute;
                        }
                        else if (attr is EntryAttribute)
                        {
                            ea = attr as EntryAttribute;
                        }
                        else if (attr is MultilineAttribute)
                        {
                            multi = true;
                        }
                        else if (attr is HtmlAttribute)
                        {
                            html = attr;
                        }
                        else if (attr is AlignmentAttribute)
                        {
                            align = attr as AlignmentAttribute;
                        }

                        if (attr is OnTapAttribute)
                        {
                            string mname = ((OnTapAttribute)attr).Method;

                            if (callbacks == null)
                            {
                                throw new Exception("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor");
                            }

                            var method = callbacks.GetType().GetMethod(mname);
                            if (method == null)
                            {
                                throw new Exception("Did not find method " + mname);
                            }
                            invoke = delegate {
                                method.Invoke(method.IsStatic ? null : callbacks, new object [0]);
                            };
                        }
                    }

                    string value = (string)GetValue(mi, o);
                    if (pa != null)
                    {
                        element = new EntryElement(caption, pa.Placeholder, value, true);
                    }
                    else if (ea != null)
                    {
                        element = new EntryElement(caption, ea.Placeholder, value)
                        {
                            KeyboardType = ea.KeyboardType, AutocapitalizationType = ea.AutocapitalizationType, AutocorrectionType = ea.AutocorrectionType, ClearButtonMode = ea.ClearButtonMode
                        }
                    }
                    ;
                    else if (multi)
                    {
                        element = new MultilineElement(caption, value);
                    }
                    else if (html != null)
                    {
                        element = new HtmlElement(caption, value);
                    }
                    else
                    {
                        var selement = new StringElement(caption, value);
                        element = selement;

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

                    if (invoke != null)
                    {
                        ((StringElement)element).Tapped += invoke;
                    }
                }
                else if (mType == typeof(float))
                {
                    var floatElement = new FloatElement(null, null, (float)GetValue(mi, o));
                    floatElement.Caption = caption;
                    element = floatElement;

                    foreach (object attr in attrs)
                    {
                        if (attr is RangeAttribute)
                        {
                            var ra = attr as RangeAttribute;
                            floatElement.MinValue    = ra.Low;
                            floatElement.MaxValue    = ra.High;
                            floatElement.ShowCaption = ra.ShowCaption;
                        }
                    }
                }
                else if (mType == typeof(bool))
                {
                    bool checkbox = false;
                    foreach (object attr in attrs)
                    {
                        if (attr is CheckboxAttribute)
                        {
                            checkbox = true;
                        }
                    }

                    if (checkbox)
                    {
                        element = new CheckboxElement(caption, (bool)GetValue(mi, o));
                    }
                    else
                    {
                        element = new BooleanElement(caption, (bool)GetValue(mi, o));
                    }
                }
                else if (mType == typeof(DateTime))
                {
                    var  dateTime = (DateTime)GetValue(mi, o);
                    bool asDate = false, asTime = false;

                    foreach (object attr in attrs)
                    {
                        if (attr is DateAttribute)
                        {
                            asDate = true;
                        }
                        else if (attr is TimeAttribute)
                        {
                            asTime = true;
                        }
                    }

                    if (asDate)
                    {
                        element = new DateElement(caption, dateTime);
                    }
                    else if (asTime)
                    {
                        element = new TimeElement(caption, dateTime);
                    }
                    else
                    {
                        element = new DateTimeElement(caption, dateTime);
                    }
                }
                else if (mType.IsEnum)
                {
                    var   csection = new Section();
                    ulong evalue   = Convert.ToUInt64(GetValue(mi, o), null);
                    int   idx      = 0;
                    int   selected = 0;

                    foreach (var fi in mType.GetFields(BindingFlags.Public | BindingFlags.Static))
                    {
                        ulong v = Convert.ToUInt64(GetValue(fi, null));

                        if (v == evalue)
                        {
                            selected = idx;
                        }

                        CaptionAttribute ca = Attribute.GetCustomAttribute(fi, typeof(CaptionAttribute)) as CaptionAttribute;
                        csection.Add(new RadioElement(ca != null ? ca.Caption : MakeCaption(fi.Name)));
                        idx++;
                    }

                    element = new RootElement(caption, new RadioGroup(null, selected))
                    {
                        csection
                    };
                }
                else if (mType == typeof(UIImage))
                {
                    element = new ImageElement((UIImage)GetValue(mi, o));
                }
                else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(mType))
                {
                    var csection = new Section();
                    int count    = 0;

                    if (last_radio_index == null)
                    {
                        throw new Exception("IEnumerable found, but no previous int found");
                    }
                    foreach (var e in (IEnumerable)GetValue(mi, o))
                    {
                        csection.Add(new RadioElement(e.ToString()));
                        count++;
                    }
                    int selected = (int)GetValue(last_radio_index, o);
                    if (selected >= count || selected < 0)
                    {
                        selected = 0;
                    }
                    element = new RootElement(caption, new MemberRadioGroup(null, selected, last_radio_index))
                    {
                        csection
                    };
                    last_radio_index = null;
                }
                else if (typeof(int) == mType)
                {
                    foreach (object attr in attrs)
                    {
                        if (attr is RadioSelectionAttribute)
                        {
                            last_radio_index = mi;
                            break;
                        }
                    }
                }
                else
                {
                    var nested = GetValue(mi, o);
                    if (nested != null)
                    {
                        var newRoot = new RootElement(caption);
                        Populate(callbacks, nested, newRoot);
                        element = newRoot;
                    }
                }

                if (element == null)
                {
                    continue;
                }
                section.Add(element);
                mappings [element] = new MemberAndInstance(mi, o);
            }
            root.Add(section);
        }
Example #5
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()
                });
            });
        }
Example #6
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() };
			});
		}
		void Populate (object callbacks, object o, RootElement root)
		{
			var members = o.GetType ().GetMembers (BindingFlags.DeclaredOnly | BindingFlags.Public |
							       BindingFlags.NonPublic | BindingFlags.Instance);

			Section section = null;
			
			foreach (var mi in members){
				Type mType = GetTypeForMember (mi);

				if (mType == null)
					continue;

				string caption = null;
				object [] attrs = mi.GetCustomAttributes (false);
				foreach (var attr in attrs){
					if (attr is CaptionAttribute)
						caption = ((CaptionAttribute) attr).Caption;
					else if (attr is SectionAttribute){
						if (section != null)
							Root.Add (section);
						var sa = attr as SectionAttribute;
						section = new Section (sa.Caption, sa.Footer);
					}
				}
				if (caption == null)
					caption = MakeCaption (mi.Name);
				
				if (section == null)
					section = new Section ();
				
				Element element = null;
				if (mType == typeof (string)){
					PasswordAttribute pa = null;
					EntryAttribute ea = null;
					NSAction invoke = null;
					bool multi = false;
					
					foreach (object attr in attrs){
						if (attr is PasswordAttribute)
							pa = attr as PasswordAttribute;
						else if (attr is EntryAttribute)
							ea = attr as EntryAttribute;
						else if (attr is MultilineAttribute)
							multi = true;
						
						if (attr is OnTapAttribute){
							string mname = ((OnTapAttribute) attr).Method;
							
							if (callbacks == null){
								throw new Exception ("Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor");
							}
							
							var method = callbacks.GetType ().GetMethod (mname);
							if (method == null)
								throw new Exception ("Did not find method " + mname);
							invoke = delegate {
								method.Invoke (method.IsStatic ? null : callbacks, new object [0]);
							};
						}
					}
					
					string value = (string) GetValue (mi, o);
					if (pa != null)
						element = new EntryElement (caption, pa.Placeholder, value, true);
					else if (ea != null)
						element = new EntryElement (caption, ea.Placeholder, value);
					else if (multi)
						element = new MultilineElement (caption, value);
					else
						element = new StringElement (caption, value);
					
					if (invoke != null)
						((StringElement) element).Tapped += invoke;
				} else if (mType == typeof (float)){
					var floatElement = new FloatElement (null, null, (float) GetValue (mi, o));
					element = floatElement;
					
					foreach (object attr in attrs){
						if (attr is RangeAttribute){
							var ra = attr as RangeAttribute;
							floatElement.MinValue = ra.Low;
							floatElement.MaxValue = ra.High;
						}
					}
				} else if (mType == typeof (bool)){
					bool checkbox = false;
					foreach (object attr in attrs){
						if (attr is CheckboxAttribute)
							checkbox = true;
					}
					
					if (checkbox)
						element = new CheckboxElement (caption, (bool) GetValue (mi, o));
					else
						element = new BooleanElement (caption, (bool) GetValue (mi, o));
				} else if (mType == typeof (DateTime)){
					var dateTime = (DateTime) GetValue (mi, o);
					bool asDate = false, asTime = false;
					
					foreach (object attr in attrs){
						if (attr is DateAttribute)
							asDate = true;
						else if (attr is TimeAttribute)
							asTime = true;
					}
					
					if (asDate)
						element = new DateElement (caption, dateTime);
					else if (asTime)
						element = new TimeElement (caption, dateTime);
					else
						 element = new DateTimeElement (caption, dateTime);
				} else if (mType.IsEnum){
					var csection = new Section ();
					ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null);
					int idx = 0;
					int selected = 0;
					
					foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){
						ulong v = Convert.ToUInt64 (GetValue (fi, null));
						
						if (v == evalue)
							selected = idx;
						
						csection.Add (new RadioElement (MakeCaption (fi.Name)));
						idx++;
					}
					
					element = new RootElement (caption, new RadioGroup (null, selected)) { csection };
				} else if (mType == typeof (UIImage)){
					element = new ImageElement ((UIImage) GetValue (mi, o));
				} else {
					var nested = GetValue (mi, o);
					if (nested != null){
						var newRoot = new RootElement (caption);
						Populate (callbacks, nested, newRoot);
						element = newRoot;
					}
				}
				
				if (element == null)
					continue;
				section.Add (element);
				mappings [element] = new MemberAndInstance (mi, o);
			}
			root.Add (section);
		}
		public BindingContext (object o, string title)
		{
			mappings = new Dictionary<Element,MemberAndInstance> ();
			var members = o.GetType ().GetMembers (BindingFlags.DeclaredOnly | BindingFlags.Public |
							       BindingFlags.NonPublic | BindingFlags.Instance);

			Root = new RootElement (title);
			Section section = null;
			
			foreach (var mi in members){
				Type mType = GetTypeForMember (mi);

				if (mType == null)
					continue;

				string caption = null;
				object [] attrs = mi.GetCustomAttributes (false);
				foreach (var attr in attrs){
					if (attr is CaptionAttribute)
						caption = ((CaptionAttribute) attr).Caption;
					else if (attr is SectionAttribute){
						if (section != null)
							Root.Add (section);
						var sa = attr as SectionAttribute;
						section = new Section (sa.Caption, sa.Footer);
					}
				}
				if (caption == null)
					caption = MakeCaption (mi.Name);
				
				if (section == null)
					section = new Section ();
				
				Element element = null;
				if (mType == typeof (string)){
					PasswordAttribute pa = null;
					EntryAttribute ea = null;
					
					foreach (object attr in attrs){
						if (attr is PasswordAttribute)
							pa = attr as PasswordAttribute;
						else if (attr is EntryAttribute)
							ea = attr as EntryAttribute;
					}
					
					if (pa != null)
						element = new EntryElement (caption, pa.Placeholder, (string) GetValue (mi, o), true);
					else if (ea != null)
						element = new EntryElement (caption, ea.Placeholder, (string) GetValue (mi, o));
					else
						element = new StringElement (caption, (string) GetValue (mi, o));
				} else if (mType == typeof (float)){
					element = new FloatElement (null, null, (float) GetValue (mi, o));
				} else if (mType == typeof (bool)){
					element = new BooleanElement (caption, (bool) GetValue (mi, o));
				} else if (mType == typeof (DateTime)){
					var dateTime = (DateTime) GetValue (mi, o);
					bool asDate = false, asTime = false;
					
					foreach (object attr in attrs){
						if (attr is DateAttribute)
							asDate = true;
						else if (attr is TimeAttribute)
							asTime = true;
					}
					
					if (asDate)
						element = new DateElement (caption, dateTime);
					else if (asTime)
						element = new TimeElement (caption, dateTime);
					else
						 element = new DateTimeElement (caption, dateTime);
				} else if (mType.IsEnum){
					var csection = new Section ();
					ulong evalue = Convert.ToUInt64 (GetValue (mi, o), null);
					int idx = 0;
					int selected = 0;
					
					foreach (var fi in mType.GetFields (BindingFlags.Public | BindingFlags.Static)){
						ulong v = Convert.ToUInt64 (GetValue (fi, null));
						
						if (v == evalue)
							selected = idx;
						
						csection.Add (new RadioElement (fi.Name));
						idx++;
					}
					
					element = new RootElement (caption, new RadioGroup (null, selected)) { csection };
				}
				
				if (element == null)
					continue;
				section.Add (element);
				mappings [element] = new MemberAndInstance (mi, o);
			}
			Root.Add (section);
		}