コード例 #1
0
        public BetPage()
        {
            try{
            this.Title = "Test Title";

            NavigationPage.SetHasNavigationBar (this, true);
            var numbersLabel = new Label { Text = "Numbers" };
            var numbersEntry = new Entry ();

            numbersEntry.SetBinding(Entry.TextProperty, "Numbers");

            var starsLabel = new Label { Text = "Stars" };
            var starsEntry = new Entry ();

            starsEntry.SetBinding(Entry.TextProperty, "Stars");

            var dateLabel = new Label { Text = "Date" };
            var dateEntry = new DatePicker ();
            dateEntry.SetBinding (DatePicker.DateProperty, new Binding ("Date", BindingMode.TwoWay, new DateTimeToStringConverter (), null));

            var saveButton = new Button { Text = "Save" };
            saveButton.Clicked += (sender, e) => {
                var BetObject = (Bet)BindingContext;
                App.Database.SaveBet(BetObject);
                this.Navigation.PopAsync();

            };

            var deleteButton = new Button { Text = "Delete" };
            deleteButton.Clicked += (sender, e) => {
                var BetObject = (Bet)BindingContext;
                App.Database.DeleteBet(BetObject.ID);
                this.Navigation.PopAsync();

            };

            var cancelButton = new Button { Text = "Cancel" };
            cancelButton.Clicked += (sender, e) => {
                this.Navigation.PopAsync();
            };

            Content = new StackLayout {
                VerticalOptions = LayoutOptions.StartAndExpand,
                Padding = new Thickness(20),
                Children = {
                    numbersLabel, numbersEntry,
                    starsLabel, starsEntry,
                    /*dateLabel, dateEntry,*/
                    saveButton, deleteButton, cancelButton
                }
            };
            }
            catch(Exception exc){
                System.Diagnostics.Debug.WriteLine (exc);
            }
        }
コード例 #2
0
        public View CreateDatePickerFor(string propertyName, LayoutOptions layout)
        {
            DatePicker iiDatePicker = new DatePicker
            {
                HorizontalOptions = layout,
                BackgroundColor = Helper.Color.iiGreen.ToFormsColor(),

            };
            iiDatePicker.SetBinding(DatePicker.DateProperty, propertyName);
            return iiDatePicker;
        }
コード例 #3
0
ファイル: NewOrderView.cs プロジェクト: njmube/VervetaCRM
        } //end ctor


        private Layout BuildView()
        {
            this.BackgroundColor = AppColors.CONTENTLIGHTBKG;

            Label lblItem = new Label() { Text = "Product:",  TextColor = AppColors.LABELBLUE };
            Picker pickerItem = new Picker() { HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = AppColors.LABELGRAY };

            foreach(var a in Order.ItemTypes)
            {
                pickerItem.Items.Add(a);
            }
            pickerItem.SetBinding(Picker.SelectedIndexProperty, "ItemIndex");

            Label lblPrice = new Label() { Text = "Price:", TextColor = AppColors.LABELBLUE };
            Entry entryPrice = new Entry() { HorizontalOptions = LayoutOptions.FillAndExpand, Keyboard = Keyboard.Numeric,
                BackgroundColor = AppColors.LABELGRAY };
            entryPrice.SetBinding(Entry.TextProperty, "Price");

            Label lblDateDue = new Label() { Text = "Date Due:", TextColor = AppColors.LABELBLUE };
            DatePicker dateDue = new DatePicker() { HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = AppColors.LABELGRAY };
            dateDue.SetBinding(DatePicker.DateProperty, "Order.DueDate");

            Button btnOrder = new Button() { Text = "Place Order", HorizontalOptions = LayoutOptions.Center, TextColor = AppColors.LABELWHITE };
            btnOrder.Clicked += btnOrder_Clicked;

            StackLayout stack = new StackLayout()
            {
                Padding = 10,

                Children =
                {
                    lblItem,
                    pickerItem,
                    lblPrice,
                    entryPrice,
                    lblDateDue,
                    dateDue,
                    btnOrder

                }

            };

            return stack;
        }
コード例 #4
0
        public TodoItemPage()
        {
            this.SetBinding(ContentPage.TitleProperty, "Todo");
            NavigationPage.SetHasNavigationBar(this, true);

            //task name
            var nameLabel = new Label { Text = "Name" };
            var nameEntry = new Entry();
            nameEntry.SetBinding(Entry.TextProperty, "Name");

            //Notes
            var notesLabel = new Label { Text = "Notes" };
            var notesEntry = new Entry();
            notesEntry.SetBinding(Entry.TextProperty, "Notes");

            //Category
            var categoryLabel = new Label { Text = "Category" };
            var categoryPicker = new Picker
            {
                Title = "Category",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            foreach (var category in App.CategoryDatabase.GetCategories())
            {
                categoryPicker.Items.Add(category.Name);
            }
            categoryPicker.SetBinding(Picker.SelectedIndexProperty, "CategoryId");

            //var categoryPicker = new BindablePicker
            //{
            //    Title = "Category",
            //    VerticalOptions = LayoutOptions.CenterAndExpand,
            //    ItemsSource = App.CategoryDatabase.GetCategoryNames()
            //};
            //categoryPicker.SetBinding(BindablePicker.SelectedItemProperty, "Category");

            //Due date
            var dueDateLabel = new Label { Text = "Due Date" };
            var dueDatePicker = new DatePicker
            {
                Format = "D",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            dueDatePicker.SetBinding(DatePicker.DateProperty, "DueDate");

            //Reminder Date
            var reminderDateLabel = new Label { Text = " Set Reminder" };
            var reminderDatePicker = new DatePicker
            {
                Format = "D",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            reminderDatePicker.SetBinding(DatePicker.DateProperty, "ReminderDate");

            //Done
            var doneLabel = new Label { Text = "Done" };
            var doneEntry = new Switch();
            doneEntry.SetBinding(Switch.IsToggledProperty, "Done");

            //Save
            var saveButton = new Button { Text = "Save" };
            saveButton.Clicked += (sender, e) =>
            {
                var todoItem = (TodoItem)BindingContext;
                App.Database.SaveItem(todoItem);
                this.Navigation.PopAsync();
            };
            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.StartAndExpand,
                Padding = new Thickness(20),
                Children = {
                    nameLabel, nameEntry,
                    notesLabel, notesEntry,
                    categoryLabel, categoryPicker,
                    dueDateLabel, dueDatePicker,
                    reminderDateLabel, reminderDatePicker,
                    doneLabel, doneEntry,
                    saveButton
                }
            };
        }
コード例 #5
0
ファイル: SaveByVMCS.cs プロジェクト: zcccust/Study
        public SaveByVMCS()
        {
            BindingContext = vm;

            var labelStyle = new Style(typeof(Label))
            {
                Setters = {
                new Setter { Property = Label.XAlignProperty, Value = TextAlignment.End },
                new Setter { Property = Label.YAlignProperty, Value = TextAlignment.Center },
                new Setter { Property = Label.WidthRequestProperty, Value = 150 }
                }
            };

            var labelName = new Label { Text = "Name:", Style = labelStyle };
            entryName = new Entry { Placeholder = "Input your name", HorizontalOptions = LayoutOptions.FillAndExpand };
            entryName.SetBinding(Entry.TextProperty, "Name", mode: BindingMode.TwoWay);

            var labelBirthday = new Label { Text = "Birthday:", Style = labelStyle };
            var pickerBirthday = new DatePicker { };
            pickerBirthday.SetBinding(DatePicker.DateProperty, "Birthday", mode: BindingMode.TwoWay);

            var labelLike = new Label { Text = "Like Xamarin?", Style = labelStyle };
            var switchLike = new Switch { };
            switchLike.SetBinding(Switch.IsToggledProperty, "Like", mode: BindingMode.TwoWay);

            var saveButton = new Button { Text = "Save", HorizontalOptions = LayoutOptions.FillAndExpand };
            saveButton.Clicked += saveButton_Clicked;
            var loadButton = new Button { Text = "Load", HorizontalOptions = LayoutOptions.FillAndExpand };
            loadButton.Clicked += loadButton_Clicked;
            var clearButton = new Button { Text = "Clear", HorizontalOptions = LayoutOptions.FillAndExpand };
            clearButton.Clicked += clearButton_Clicked;
            resultLabel = new Label { Text = "", FontSize = 30 };

            Title = "Save to dic by vm (C#)";
            Content = new StackLayout
            {
                Padding = 10,
                Spacing = 10,
                Children = {
                    new Label { Text = "DataSave Sample", FontSize = 40, HorizontalOptions = LayoutOptions.Center },
                    new StackLayout {
                        Orientation = StackOrientation.Horizontal,
                        Children = {
                            labelName, entryName
                        }
                    },
                    new StackLayout {
                        Orientation = StackOrientation.Horizontal,
                        Children = {
                            labelBirthday, pickerBirthday
                        }
                    },
                    new StackLayout {
                        Orientation = StackOrientation.Horizontal,
                        Children = {
                            labelLike, switchLike
                        }
                    },
                    new StackLayout {
                        Orientation = StackOrientation.Horizontal,
                        Children = {
                            saveButton, loadButton, clearButton
                        }
                    },
                    resultLabel
                }
            };
        }
コード例 #6
0
ファイル: ExpensesPage.cs プロジェクト: Benesss/ExpenseForms
		private void CreateControls()
		{
			var list = new ListView(ListViewCachingStrategy.RecycleElement) { ItemTemplate = new DataTemplate(typeof(ExpenseCell)) };
			list.ItemSelected += (sender, e) =>
			{
					((ListView)sender).SelectedItem = null;
			};
			list.SetBinding<ExpenseViewModel>(ListView.ItemsSourceProperty, vm => vm.Expenses);
			this.SetBinding<ExpenseViewModel>(TitleProperty, vm => vm.Title);

			var footer = new Grid { /*HeightRequest = 120,*/ BackgroundColor = AppColors.Gray.MultiplyAlpha(0.5d), RowSpacing = 10, Padding = new Thickness(0, 0, 0, 10) };
			footer.RowDefinitions.Add(new RowDefinition { Height = 1 });
			footer.RowDefinitions.Add(new RowDefinition());
			footer.RowDefinitions.Add(new RowDefinition());
			footer.RowDefinitions.Add(new RowDefinition());
			footer.ColumnDefinitions.Add(new ColumnDefinition());
			footer.ColumnDefinitions.Add(new ColumnDefinition());

			var topBorder = new StackLayout { BackgroundColor = AppColors.DarkGray };
			footer.Children.Add(topBorder);
			Grid.SetColumn(topBorder, 0);
			Grid.SetRow(topBorder, 0);
			Grid.SetColumnSpan(topBorder, 2);

			var picker = new DatePicker { Format = "MMMMM yyyy", BackgroundColor = Color.Transparent, HorizontalOptions = LayoutOptions.Center };
			footer.Children.Add(picker);
			picker.SetBinding<ExpenseViewModel>(DatePicker.DateProperty, vm => vm.SelectedDate);
			Grid.SetRow(picker, 1);
			Grid.SetColumnSpan(picker, 2);

			var manGroup = new StackLayout { Orientation = StackOrientation.Horizontal, Padding = new Thickness(10, 0) };
			var manLabel = CreateLabel("Ben :", 18, AppColors.DarkGray);
			manLabel.FontAttributes = FontAttributes.Bold;
			var manValue = CreateLabel("", 16, AppColors.Blue);
			manValue.SetBinding<ExpenseViewModel>(Label.TextProperty, vm => vm.ManTotal, BindingMode.Default, new FloatCurrenyValueConverter());
			manGroup.Children.Add(manLabel);
			manGroup.Children.Add(manValue);
			footer.Children.Add(manGroup);
			Grid.SetColumn(manGroup, 0);
			Grid.SetRow(manGroup, 2);

			var womanGroup = new StackLayout { Orientation = StackOrientation.Horizontal, Padding = new Thickness(10, 0) };
			var womanLabel = CreateLabel("Soph :", 18, AppColors.DarkGray);
			womanLabel.FontAttributes = FontAttributes.Bold;
			var womanValue = CreateLabel("", 16, AppColors.Red);
			womanValue.SetBinding<ExpenseViewModel>(Label.TextProperty, vm => vm.WomanTotal, BindingMode.Default, new FloatCurrenyValueConverter());
			womanGroup.Children.Add(womanLabel);
			womanGroup.Children.Add(womanValue);
			footer.Children.Add(womanGroup);
			Grid.SetColumn(womanGroup, 0);
			Grid.SetRow(womanGroup, 3);

			var totalGroup = new StackLayout { Orientation = StackOrientation.Horizontal, Padding = new Thickness(10, 0) };
			var totalLabel = CreateLabel("TOTAL :", 18, AppColors.DarkGray);
			totalLabel.FontAttributes = FontAttributes.Bold;
			var totalValue = CreateLabel("", 16, AppColors.DarkGray.MultiplyAlpha(0.8d));
			totalValue.SetBinding<ExpenseViewModel>(Label.TextProperty, vm => vm.BothTotal, BindingMode.Default, new FloatCurrenyValueConverter());
			totalGroup.Children.Add(totalLabel);
			totalGroup.Children.Add(totalValue);
			footer.Children.Add(totalGroup);
			Grid.SetColumn(totalGroup, 1);
			Grid.SetRow(totalGroup, 2);

			var differenceGroup = new StackLayout { Orientation = StackOrientation.Horizontal, Padding = new Thickness(10, 0) };
			var differenceLabel = CreateLabel("Différence :", 18, AppColors.DarkGray);
			differenceLabel.FontAttributes = FontAttributes.Bold;
			var differenceValue = CreateLabel("", 16, AppColors.Orange);
			differenceValue.SetBinding<ExpenseViewModel>(Label.TextProperty, vm => vm.Diff);
			differenceGroup.Children.Add(differenceLabel);
			differenceGroup.Children.Add(differenceValue);
			footer.Children.Add(differenceGroup);
			Grid.SetColumn(differenceGroup, 1);
			Grid.SetRow(differenceGroup, 3);

			var all = new StackLayout { Orientation = StackOrientation.Vertical };
			all.Children.Add(list);
			all.Children.Add(footer);

			Content = all;

			ToolbarItems.Add(new ToolbarItem
				{
					Command = _vm.ShowAddCommand,
					Icon = new FileImageSource { File = "add.png" }
				});
		}
コード例 #7
0
ファイル: SignUp.cs プロジェクト: jamesqquick/XamarinForms
        public SignUp()
        {
            Label title = new Label {
                Text = "Sign Up",
                FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center,
            };

            //Label and Entry for Name
            Label name = new Label {
                Text = "Name",
                FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center
            };
            Entry nameEntry = new Entry {
                HorizontalOptions = LayoutOptions.Fill,
            };
            nameEntry.SetBinding (Entry.TextProperty, "Name");

            //Label and Entry for Email
            Label email = new Label {
                Text = "Email",
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center
            };
            Entry emailEntry = new Entry {
                HorizontalOptions = LayoutOptions.Fill,
            };
            emailEntry.SetBinding (Entry.TextProperty, "Email");

            //Label and DatePicker for Birthdate
            Label birthdate = new Label {
                Text = "Birthdate",
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center
            };
            DatePicker datePicker = new DatePicker {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
            datePicker.SetBinding (DatePicker.DateProperty, "Birthdate");

            //Button to save user
            Button saveButton = new Button {
                HorizontalOptions = LayoutOptions.Center,
                WidthRequest = 100,
                Text ="Save",
                BorderWidth = 1,
            };
            saveButton.SetBinding (Button.CommandProperty, "SaveUserCommand");

            //Set the binding context to the UserViewModel
            vm = new UserViewModel();
            this.BindingContext = vm;
            //Add padding to support IPhone top bar
            this.Padding = new Thickness (0, Device.OnPlatform (20, 0, 0), 0, 0);

            StackLayout stack = new StackLayout {
                Children = {title, name, nameEntry, email, emailEntry, birthdate, datePicker, saveButton}
            };
            this.Content = stack;

            //Listen for messages from the view model
            MessagingCenter.Subscribe<UserViewModel, string> (this, "save message", (sender, arg) => {

                if(arg.Equals("Empty fields"))
                    DisplayAlert("Missing Fields", "Ensure all of the fields are completed", "Close");
                if(arg.Equals("Invalid email"))
                    DisplayAlert("Invalid Email", "Please, ensure your email address is correct", "Close");
                if(arg.Equals("Success")){
                    DisplayAlert("Sign up successful", String.Format("Thank you {0} for signing up", ((UserViewModel)this.BindingContext).Name), "Close");
                    ((UserViewModel)this.BindingContext).Name="";
                    ((UserViewModel)this.BindingContext).Email="";
                    ((UserViewModel)this.BindingContext).Birthdate=DateTime.Now;
                }
            });
        }
コード例 #8
0
        public RegistrationPage(bool isUpdate, Page parent, UserAccount userAccount = null)
        {
            InitializeComponent();
            if (!isUpdate)
            {
                Title = "Registration";
            }
            else
            {
                Title = "Update Information";
            }
            _tableView.Intent = TableIntent.Menu;

            if (userAccount == null)
            {
                _viewModel = new AccountInfoViewModel();
            }
            else
            {
                _viewModel = new AccountInfoViewModel(userAccount);
            }
            this.BindingContext = _viewModel;

            #region Birthday
            var birthdayCell = new ViewCell();
            _birthdaySection.Add(birthdayCell);

            var birthdayLayout = new StackLayout
            {
                Padding = new Thickness(10, 0, 10, 0),
            };
            birthdayCell.View = birthdayLayout;

            var datePicker = new DatePicker
            {
                Format = "MMM d yyyy",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };
            birthdayLayout.Children.Add(datePicker);
            datePicker.SetBinding(DatePicker.DateProperty, "UserAccount.Birthday", BindingMode.TwoWay);
            #endregion

            #region Province
            var provinceCellLayout = new StackLayout
            {
                Padding = new Thickness(10, 0, 10, 0),
            };
            _provinceCell.View = provinceCellLayout;

            var provincePicker = new Picker
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };
            provinceCellLayout.Children.Add(provincePicker);

            var firstCountry = DatabaseManager.DbConnection.Table<Country>().First();
            var provinces = DatabaseManager.DbConnection.Table<Province>().Where(x => x.CountryCode == firstCountry.CountryCode).ToList();
            foreach (var province in provinces)
            {
                provincePicker.Items.Add(province.ProvinceName);
            }
            provincePicker.SetBinding(Picker.SelectedIndexProperty, new Binding("UserAccount.Province", BindingMode.TwoWay, new PickerProvinceToIndexConverter(), provinces));
            #endregion

            #region Country
            var countryCellLayout = new StackLayout
            {
                Padding = new Thickness(10, 0, 10, 0),
            };
            _countryCell.View = countryCellLayout;

            var countryPicker = new Picker
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };
            countryCellLayout.Children.Add(countryPicker);

            var countries = DatabaseManager.DbConnection.Table<Country>().ToList();
            foreach (var country in countries)
            {
                countryPicker.Items.Add(country.CountryName);
            }
            countryPicker.SetBinding(Picker.SelectedIndexProperty, new Binding("UserAccount.Country", BindingMode.TwoWay, new PickerCountryToIndexConverter(), countries));

            countryPicker.SelectedIndexChanged += (sender, e) =>
            {
                provincePicker.Items.Clear();

                var countryCode = countries[countryPicker.SelectedIndex].CountryCode;
                var newProvinces = DatabaseManager.DbConnection.Table<Province>().Where(x => x.CountryCode == countryCode).ToList();

                // If there is no province, use N/A
                if ((newProvinces == null) || (newProvinces.Count == 0))
                {
                    newProvinces = new List<Province>
                    {
                        new Province
                        {
                            ProvinceName = "N/A",
                        }
                    };
                }

                foreach (var province in newProvinces)
                {
                    provincePicker.Items.Add(province.ProvinceName);
                }
                provincePicker.SetBinding(Picker.SelectedIndexProperty, new Binding("UserAccount.Province", BindingMode.TwoWay, new PickerProvinceToIndexConverter(), newProvinces));
            };
            #endregion

            #region Raffle Result
            var raffleResultsViewCell = new ViewCell();
            _raffleResultsSection.Add(raffleResultsViewCell);

            var raffleResultsLayout = new StackLayout
            {
                Padding = new Thickness(10, 0, 10, 0),
            };
            raffleResultsViewCell.View = raffleResultsLayout;

            var raffleResultsPicker = new Picker
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };
            raffleResultsLayout.Children.Add(raffleResultsPicker);

            foreach (var item in c_contactMethods)
            {
                raffleResultsPicker.Items.Add(item);
            }
            raffleResultsPicker.SetBinding(Picker.SelectedIndexProperty, new Binding("UserAccount.PreferedContactMethod", BindingMode.TwoWay, new PickerContactMethodsConverter()));
            #endregion

            #region Charity Message
            var charityMessagesViewCell = new ViewCell();
            _charityMessagesSection.Add(charityMessagesViewCell);

            var charityMessagesLayout = new StackLayout
            {
                Padding = new Thickness(10, 0, 10, 0),
            };
            charityMessagesViewCell.View = charityMessagesLayout;

            var charityMessagesPicker = new Picker
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };
            charityMessagesLayout.Children.Add(charityMessagesPicker);

            foreach (var item in c_contactMethods)
            {
                charityMessagesPicker.Items.Add(item);
            }
            charityMessagesPicker.SetBinding(Picker.SelectedIndexProperty, new Binding("UserAccount.PreferedContactMethodCharity", BindingMode.TwoWay, new PickerContactMethodsConverter()));
            #endregion

            if (!isUpdate)
            {
                var createAccountButtonViewCell = new ViewCell();
                _createAccountButtonSection.Add(createAccountButtonViewCell);

                var createAccountButtonLayout = new StackLayout
                {
                    Padding = new Thickness(5, 0, 5, 0),
                    BackgroundColor = Color.Accent,
                };
                createAccountButtonViewCell.View = createAccountButtonLayout;

                var createAccountButton = new Button
                {
                    Text = "Create Account",
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    TextColor = Color.White,
                };
                createAccountButtonLayout.Children.Add(createAccountButton);

                createAccountButton.Clicked += async (sender, e) =>
                {
                    var result = await _viewModel.CreateAccount();
                    if (result.Item1)
                    {
                        this.Navigation.PopAsync();
                        var answer = await DisplayAlert("Register Phone Number", "Send registration code to your phone now?", "Later", "Yes");
                        if (!answer) // use !answer because the negative choice has a bigger font
                        {
                            parent.Navigation.PushAsync(new VerifyPhonePage(_viewModel.UserAccount.Email, _viewModel.UserAccount.Phone, _viewModel.UserAccount.CountryCode)); //Country code is updated after calling _viewModel.CreateAccount()
                        }
                    }
                    else
                    {
                        DisplayAlert("Server request failed", "", "OK");
                    }
                };
            }
            else
            {
                // Edit Account Page
                _toolbarItemIsEnabled = true;

                _onDoneButtonClicked = new Command(async () =>
                    {
                        if (_toolbarItemIsEnabled)
                        {
                            if (_viewModel.InfoHasNotChanged())
                            {
                                DisplayAlert("Warning", "Your information has not changed.", "Retry");
                            }
                            else
                            {
                                _toolbarItemIsEnabled = false; // Disable the button while await
                                var result = await _viewModel.UpdateAccountInfo();
                                _toolbarItemIsEnabled = true;
                                if (result.Item1)
                                {
                                    this.Navigation.InsertPageBefore(new AccountInfoPage(), parent);
                                    this.Navigation.PopAsync(false);
                                    this.Navigation.PopAsync(false);
                                }
                                else
                                {
                                    DisplayAlert("Error", result.Item2, "Retry");
                                }
                            }
                        }
                    });

                var toolbarItem = new ToolbarItem
                {
                    Text = "Done",
                    Command = _onDoneButtonClicked,
                };
                this.ToolbarItems.Add(toolbarItem);
            }
        }
コード例 #9
0
        public ConfigView(ConfigViewModel configViewModel)
        {
            BindingContext = configViewModel;
            Title = "Configurações";

            ToolbarItems.Add (new ToolbarItem {
                Text = "Sair",
                Order = ToolbarItemOrder.Primary,
                Command = new Command (ActionSair)
            });

            datePickerInicio = new DatePicker {
                Format = "dd, MMM",
                VerticalOptions = LayoutOptions.CenterAndExpand,

            };
            datePickerFim = new DatePicker {
                Format = "dd, MMM",
                VerticalOptions = LayoutOptions.CenterAndExpand,

            };

            // Accomodate iPhone status bar.
            this.Padding = new Thickness (10, Device.OnPlatform (0, 0, 0), 1, 1);

            StackLayout stack = new StackLayout {
                Orientation = StackOrientation.Horizontal,
                Padding = new Thickness (10, 0, 10, 0),
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children = {
                    new StackLayout {
                        Orientation = StackOrientation.Horizontal,
                        VerticalOptions = LayoutOptions.FillAndExpand,
                        HorizontalOptions = LayoutOptions.StartAndExpand,
                        Children = {
                            new Label {
                                VerticalOptions = LayoutOptions.CenterAndExpand,
                                HorizontalOptions = LayoutOptions.StartAndExpand,
                                Text = "Inicial",
                                Style = Styles.DefaultCellText
                            },
                            datePickerInicio
                        }
                    },
                    new StackLayout {
                        Orientation = StackOrientation.Horizontal,
                        VerticalOptions = LayoutOptions.FillAndExpand,
                        HorizontalOptions = LayoutOptions.CenterAndExpand,
                        Children = {
                            new Label {
                                VerticalOptions = LayoutOptions.CenterAndExpand,
                                HorizontalOptions = LayoutOptions.StartAndExpand,
                                Text = "Final",
                                Style = Styles.DefaultCellText
                            },
                            datePickerFim
                        }
                    }
                }
            };

            SwitchCell EnableHolidaySwitch = new SwitchCell {
                Text = "Habilitar horário de verão",
                On = Settings.HolidayState
            };

            ViewCell viewCell = new ViewCell { View = stack };

            //			EnableHolidaySwitch.SetBinding (IsVisibleProperty, "IsVisible");
            //			viewCell.SetBinding (IsVisibleProperty, "IsVisible");
            TableSection firstSection = new TableSection ("Horario de verão") {
                viewCell,
                EnableHolidaySwitch
            };

            ConfigTable = new TableView {
                Intent = TableIntent.Settings,
                BackgroundColor = Color.Transparent,
                Root = new TableRoot {
                    firstSection,
                    new TableSection () {
                        new SwitchCell { Text = "Segurança" },
                    },
                    new TableSection ("Rede") {
                        new SwitchCell { Text = "Sincronizar apenas via Wi-Fi" }
                    },
                }
            };

            try {
                datePickerInicio.SetBinding (DatePicker.DateProperty, "MysafetyUser.IVerao", BindingMode.TwoWay, new StringDateConverter ());
                datePickerInicio.DateSelected += datePickerInicio_DateSelected;
                datePickerFim.SetBinding (DatePicker.DateProperty, "MysafetyUser.FVerao", BindingMode.TwoWay, new StringDateConverter ());
                datePickerFim.DateSelected += datePickerFim_DateSelected;
            } catch (Exception ex) {
                Debug.WriteLine ("Exception " + ex.Message);
            }

            ConfigTable.GetSwitchCell (1, 0).SetBinding (SwitchCell.OnProperty, "MysafetyUser.Stext", BindingMode.TwoWay, new NullBoolenConverter ());
            ConfigTable.GetSwitchCell (1, 0).OnChanged += (object sender, ToggledEventArgs e) => {
                if (ConfigTable.GetSwitchCell (1, 0).On)
                    Navigation.PushModalAsync (new LockScreen (new LockScreenViewModel (Navigation)), true);
                else
                    Navigation.PushModalAsync (new LockScreen (new LockScreenViewModel (Navigation, LockScreenViewModel.Actions.DisablePassword)), true);
                ((ConfigViewModel)BindingContext).Save ();
            };

            ConfigTable.GetSwitchCell (2, 0).SetBinding (SwitchCell.OnProperty, "MysafetyUser.SyncWiFi", BindingMode.TwoWay, new NullBoolenConverter ());
            ConfigTable.GetSwitchCell (2, 0).OnChanged += (object sender, ToggledEventArgs e) => {
                ((ConfigViewModel)BindingContext).Save ();
            };

            ConfigTable.GetSwitchCell (0, 1).OnChanged += (object sender, ToggledEventArgs e) => {
                if (ConfigTable.GetSwitchCell (0, 1).On) {
                    datePickerInicio.IsEnabled = true;
                    datePickerFim.IsEnabled = true;

                } else {
                    datePickerInicio.IsEnabled = false;
                    datePickerFim.IsEnabled = false;
                }
                Settings.HolidayState = ConfigTable.GetSwitchCell (0, 1).On;
            };

            Content = ConfigTable;

            //			if (App.Gates.Count > 0)
            //				ConfigTable.Root.Insert (0, firstSection);
            //			else
            //				ConfigTable.Root.Remove (firstSection);
        }