示例#1
0
        public PaymentViewController(string title) : base(UITableViewStyle.Grouped, null, true)
        {
            var eleCardNumber = new EntryElement(string.Empty, "Kort nummer", this.ViewModel.CardNumber)
            {
                KeyboardType = UIKeyboardType.NumberPad
            };
            var eleExpirationDate = new StringElement("Udløbs dato", this.ViewModel.ExpirationDate.ToString("MM-yy"));
            var eleSecurityCode   = new EntryElement(string.Empty, "Sikkerheds kode", this.ViewModel.SecurityCode)
            {
                KeyboardType = UIKeyboardType.NumberPad
            };

            this.Root = new RootElement(title)
            {
                new Section
                {
                    eleCardNumber,
                    eleExpirationDate,
                    eleSecurityCode
                }
            };

            eleCardNumber.BindText(this.ViewModel, vm => vm.CardNumber);
            eleExpirationDate.BindText(this.ViewModel, vm => this.ViewModel.ExpirationDateText);
            eleSecurityCode.BindText(this.ViewModel, vm => this.ViewModel.SecurityCode);

            eleExpirationDate.Tapped += this.EleExpirationDateOnTapped;

            this.toolbar = new UIToolbar(new CGRect(0, 0, 320, 44));
            this.toolbar.SetItems(new[]
            {
                new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                new UIBarButtonItem(UIBarButtonSystemItem.Done, (s, e) => this.View.EndEditing(true)),
            }, false);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var eleFirstName = new EntryElement(string.Empty, "Fornavn", this.ViewModel.FirstName)
            {
                AutocapitalizationType = UITextAutocapitalizationType.Words,
                AutocorrectionType     = UITextAutocorrectionType.No
            };
            var eleLastName = new EntryElement(string.Empty, "Efternavn", this.ViewModel.LastName)
            {
                AutocapitalizationType = UITextAutocapitalizationType.Words,
                AutocorrectionType     = UITextAutocorrectionType.No
            };

            var eleEmail = new EntryElement(string.Empty, "Email", this.ViewModel.Email)
            {
                KeyboardType           = UIKeyboardType.EmailAddress,
                AutocorrectionType     = UITextAutocorrectionType.No,
                AutocapitalizationType = UITextAutocapitalizationType.None
            };
            var elePassword       = new EntryElement(string.Empty, "Kodeord", this.ViewModel.Password, true);
            var elePasswordRepeat = new EntryElement(string.Empty, "Gentag kodeord", this.ViewModel.PasswordRepeat, true);
            var eleUsername       = new EntryElement(string.Empty, "Brugernavn", this.ViewModel.Username)
            {
                AutocorrectionType     = UITextAutocorrectionType.No,
                AutocapitalizationType = UITextAutocapitalizationType.None
            };

            this.Root = new RootElement("Registrer")
            {
                new Section("Personlige oplysninger")
                {
                    eleFirstName,
                    eleLastName,
                },
                new Section("Konto oplysninger")
                {
                    eleEmail,
                    elePassword,
                    elePasswordRepeat,
                    eleUsername
                }
            };

            eleFirstName.BindText(this.ViewModel, vm => vm.FirstName);
            eleLastName.BindText(this.ViewModel, vm => vm.LastName);

            eleEmail.BindText(this.ViewModel, vm => vm.Email);
            elePassword.BindText(this.ViewModel, vm => vm.Password);
            elePasswordRepeat.BindText(this.ViewModel, vm => vm.PasswordRepeat);
            eleUsername.BindText(this.ViewModel, vm => vm.Username);
        }
        public CreateAccountViewController()
            : base(UITableViewStyle.Grouped, null, true)
        {
            this.ViewModel = new CreateAccountViewModel();

            var eleAcceptTos = new BooleanElement("Accept", this.ViewModel.ToS);

            eleAcceptTos.BindValue(this.ViewModel, vm => vm.ToS);

            var eleFirstName = new EntryElement("First name", "Enter first name", this.ViewModel.FirstName);

            eleFirstName.BindText(this.ViewModel, vm => vm.FirstName);

            var eleLastName = new EntryElement("Last name", "Enter last name", this.ViewModel.LastName);

            eleLastName.BindText(this.ViewModel, vm => vm.LastName);

            var eleBirthday = new DateElement("Birthday", this.ViewModel.Birthday);

            eleBirthday.BindDate(this.ViewModel, vm => vm.Birthday);

            var btnLogin = new UIButton {
                BackgroundColor = UIColor.White, Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 64)
            };

            btnLogin.SetTitle("Create Account", UIControlState.Normal);
            btnLogin.SetTitleColor(UIColor.Green, UIControlState.Normal);
            btnLogin.SetTitleColor(UIColor.DarkGray, UIControlState.Disabled);
            btnLogin.BindEnable(this.ViewModel, vm => vm.ToS);
            btnLogin.TouchUpInside += (sender, args) => this.CreateAccount();

            var eleUsername = new EntryElement("Login", "Enter desired login", this.ViewModel.Username);

            eleUsername.BindText(this.ViewModel, vm => vm.Username);

            var elePassword = new EntryElement("Password", "Enter desired password", this.ViewModel.Password, true);

            elePassword.BindText(this.ViewModel, vm => vm.Password);

            const string NavTitle = "Bindings";

            this.Root = new RootElement(NavTitle)
            {
                new Section("Personal")
                {
                    eleFirstName,
                    eleLastName,
                    eleBirthday
                },
                new Section("Account")
                {
                    eleUsername,
                    elePassword
                },
                new Section("Read the Terms of Service")
                {
                    eleAcceptTos
                },
                new Section
                {
                    new UIViewElement(string.Empty, btnLogin, true)
                }
            };

            Action <CreateAccountViewController, string> updateTitle = (c, text) =>
            {
                if (this.NavigationItem == null)
                {
                    return;
                }

                if (!string.IsNullOrEmpty(this.ViewModel.FirstName) &&
                    !string.IsNullOrEmpty(this.ViewModel.LastName))
                {
                    this.NavigationItem.Title = $"{this.ViewModel.FirstName} {this.ViewModel.LastName}";
                }
                else
                {
                    this.NavigationItem.Title = NavTitle;
                }
            };

            BindingCore.CreateBinding(this, this.ViewModel, vm => vm.FirstName, updateTitle);
            BindingCore.CreateBinding(this, this.ViewModel, vm => vm.LastName, updateTitle);
        }