Example #1
0
        protected virtual FrameworkElement CreateTimePicker()
        {
            var picker = new TimePicker();

            picker.SetBinding(TimePicker.HeaderProperty, new Binding()
            {
                Source = this,
                Path   = new PropertyPath(nameof(Header))
            });

            picker.SetBinding(TimePicker.TimeProperty, new Binding()
            {
                Source = this,
                Path   = new PropertyPath(nameof(SelectedTime)),
                Mode   = BindingMode.TwoWay
            });

            return(picker);
        }
        private CompressedStackLayout CreateEndDateTimePanel()
        {
            var evtEndDate = new Label()
            {
                TextColor = Color.Gray,
                Text      = "End Date",
                FontSize  = 14,
                Margin    = new Thickness(5, 5, 5, 1)
            };

            var evtEndDateEntry = new DatePicker()
            {
                Margin       = new Thickness(5, 1, 5, 1),
                AutomationId = "evtEndDateEntry"
            };

            evtEndDateEntry.SetBinding(DatePicker.DateProperty, "Appt.EndDate");

            var endDatePanel = new StackLayout()
            {
                Children = { evtEndDate, evtEndDateEntry }
            };

            var evtEndTime = new Label()
            {
                TextColor = Color.Gray,
                Text      = "End Time",
                FontSize  = 14,
                Margin    = new Thickness(5, 5, 5, 1)
            };

            var evtEndTimeEntry = new TimePicker()
            {
                Margin       = new Thickness(5, 1, 5, 1),
                AutomationId = "evtEndTimeEntry"
            };

            evtEndTimeEntry.SetBinding(TimePicker.TimeProperty, "EndTime");

            var endTimePanel = new StackLayout()
            {
                Children = { evtEndTime, evtEndTimeEntry }
            };

            var endDateTimePanel = new CompressedStackLayout()
            {
                Orientation = StackOrientation.Horizontal,
                Children    = { endDatePanel, endTimePanel }
            };

            return(endDateTimePanel);
        }
Example #3
0
        private StackContainer CreateStartDateTimePanel()
        {
            var evtStartDate = new Label()
            {
                TextColor = Color.Gray,
                Text      = "Start Date",
                FontSize  = 14,
                Margin    = new Thickness(5, 5, 5, 1)
            };

            var evtStartDateEntry = new DatePicker()
            {
                Margin       = new Thickness(5, 1, 5, 1),
                AutomationId = "evtStartDateEntry",
            };

            evtStartDateEntry.SetBinding(DatePicker.DateProperty, "Appt.StartDate");

            var startDatePanel = new StackLayout()
            {
                Children = { evtStartDate, evtStartDateEntry }
            };

            var evtStartTime = new Label()
            {
                TextColor = Color.Gray,
                Text      = "Start Time",
                FontSize  = 14,
                Margin    = new Thickness(5, 5, 5, 1)
            };

            var evtStartTimeEntry = new TimePicker()
            {
                Margin       = new Thickness(5, 1, 5, 1),
                AutomationId = "evtStartTimeEntry"
            };

            evtStartTimeEntry.SetBinding(TimePicker.TimeProperty, "StartTime");

            var startTimePanel = new StackLayout()
            {
                Children = { evtStartTime, evtStartTimeEntry }
            };

            var startDateTimePanel = new StackContainer(true)
            {
                Orientation = StackOrientation.Horizontal,
                Children    = { startDatePanel, startTimePanel }
            };

            return(startDateTimePanel);
        }
Example #4
0
        public override Control ProvideControl(PropertyInfo propertyInfo, object viewModel)
        {
            Binding binding = propertyInfo.GetBinding();

            var editableAttribute = propertyInfo.GetAttribute <EditableAttribute>();

            Control control = new TimePicker();

            control.SetBinding(TimePicker.ValueProperty, binding);
            control.IsEnabled = propertyInfo.IsControlEnabled();


            return(control);
        }
Example #5
0
        public override Control ProvideControl(PropertyInfo propertyInfo, object viewModel)
        {
            Binding binding = propertyInfo.GetBinding();

            var editableAttribute = propertyInfo.GetAttribute <EditableAttribute>();

            Control control = new TimePicker();

            control.SetBinding(TimePicker.ValueProperty, binding);
            control.IsEnabled = editableAttribute == null || editableAttribute.AllowEdit ||
                                binding.Mode == BindingMode.TwoWay;


            return(control);
        }
Example #6
0
        public async Task When_SettingNullTime_ShouldNotCrash()
        {
            var timePicker = new TimePicker();

            timePicker.SetBinding(TimePicker.TimeProperty, new Binding {
                Path = new PropertyPath("StartTime")
            });

            var root = new Grid
            {
                DataContext = new MyContext()
            };

            root.Children.Add(timePicker);

            TestServices.WindowHelper.WindowContent = root;

            await TestServices.WindowHelper.WaitForIdle();
        }
Example #7
0
        protected override View CreateControl(string bindingName, Type fieldType)
        {
            if (fieldType != typeof(DateTime) &&
                fieldType != typeof(DateTimeOffset) &&
                fieldType != typeof(DateTime?) &&
                fieldType != typeof(DateTimeOffset?))
            {
                Debug.WriteLine($"field:{bindingName} error. Wrong type {fieldType.ToString()} should be DateTime or DateTimeOffset");
                return null;
            }

            var date = new DatePicker
            {
                Style = _itemStyle
            };
            date.SetBinding(DatePicker.DateProperty, new Binding(bindingName, BindingMode.TwoWay, new DateTimeConverter(), fieldType));

            var time = new TimePicker
            {
                Style = _itemStyle
            };
            time.SetBinding(TimePicker.TimeProperty, new Binding(bindingName, BindingMode.TwoWay, new DateTimeConverter(), fieldType));
            Grid.SetRow(time, 1);

            var g = new Grid
            {
                VerticalOptions = LayoutOptions.StartAndExpand,
                RowDefinitions =
                    {
                        new RowDefinition {Height = GridLength.Auto},
                        new RowDefinition {Height = GridLength.Auto},
                    },
                Children =
                {
                    date,
                    time,
                }
            };

            return g;
        }
Example #8
0
        private StackLayout ObterFormHora()
        {
            StackLayout layoutPrincipal = ObterLayoutPrincipal();

            StackLayout layoutHora = new StackLayout();

            layoutHora.Padding           = new Thickness(0, 0, 0, 0);
            layoutHora.HorizontalOptions = LayoutOptions.CenterAndExpand;

            TimePicker tp = new TimePicker();

            tp.Time   = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            tp.Format = "HH:mm";

            tp.SetBinding(TimePicker.TimeProperty, new Binding("HoraSelecionada", BindingMode.TwoWay));

            layoutHora.Children.Add(tp);

            layoutPrincipal.Children.Add(layoutHora);
            layoutPrincipal.Children.Add(ObterLayoutBotoes());

            return(layoutPrincipal);
        }
Example #9
0
        private void InitTableView()
        {
            var bindingContext = BindingContext as VisitResultViewModel;
            int paddingLeft    = Convert.ToInt32(Application.Current.Resources["paddingLeftFormViewCell"]);

            TableView tableView = new TableView
            {
                Intent        = TableIntent.Form,
                Root          = new TableRoot("Esito visita"),
                HasUnevenRows = true
            };

            tableView.SetBinding(TableView.IsVisibleProperty, nameof(bindingContext.IsReady));

            #region Clients List Picker
            Picker clientsListPicker = new Picker();
            clientsListPicker.Title = "Seleziona cliente";
            clientsListPicker.SetBinding(Picker.ItemsSourceProperty, nameof(bindingContext.ClientsList));
            clientsListPicker.SetBinding(Picker.SelectedItemProperty, nameof(bindingContext.ClientName));
            tableView.Root.Add(new TableSection("Cliente")
            {
                new ViewCell()
                {
                    View = clientsListPicker
                }
            });
            #endregion

            #region Contact
            EntryCell contactName = new EntryCell();
            contactName.Label       = "Contatto:";
            contactName.Placeholder = "Nome Contatto";
            contactName.SetBinding(EntryCell.TextProperty, nameof(bindingContext.ContactName));
            EntryCell contactPhone = new EntryCell();
            contactPhone.Label       = "Telefono:";
            contactPhone.Placeholder = "Numero di telefono";
            contactPhone.Keyboard    = Keyboard.Telephone;
            contactPhone.SetBinding(EntryCell.TextProperty, nameof(bindingContext.ContactPhone));
            EntryCell contactEmail = new EntryCell();
            contactEmail.Label       = "Email:";
            contactEmail.Placeholder = "Indirizzo email";
            contactEmail.Keyboard    = Keyboard.Email;
            contactEmail.SetBinding(EntryCell.TextProperty, nameof(bindingContext.ContactEmail));
            EntryCell contactWebSite = new EntryCell();
            contactWebSite.Label       = "Web:";
            contactWebSite.Placeholder = "Indirizzo sito web";
            contactWebSite.Keyboard    = Keyboard.Url;
            contactWebSite.SetBinding(EntryCell.TextProperty, nameof(bindingContext.ContactWebSite));
            tableView.Root.Add(new TableSection("Contatto")
            {
                contactName,
                contactPhone,
                contactEmail,
                contactWebSite
            });
            #endregion

            #region Visit Date and Time
            DatePicker visitDatePicker = new DatePicker();
            visitDatePicker.SetBinding(DatePicker.DateProperty, nameof(bindingContext.VisitDate));
            TimePicker visitTimePicker = new TimePicker();
            visitTimePicker.SetBinding(TimePicker.TimeProperty, nameof(bindingContext.VisitTime));
            tableView.Root.Add(new TableSection("Data e Ora Visita")
            {
                new ViewCell()
                {
                    View = new StackLayout()
                    {
                        Orientation       = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.Center,
                        Children          = { visitDatePicker, visitTimePicker }
                    }
                }
            });
            #endregion

            #region Visit Interview

            #region Is Interested
            SwitchCell isInterested = new SwitchCell()
            {
                Text = "Interessato"
            };
            isInterested.SetBinding(SwitchCell.OnProperty, nameof(bindingContext.IsInterested));
            #endregion

            #region Quantity
            Entry quantity = new Entry()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand, HorizontalTextAlignment = TextAlignment.End
            };
            quantity.SetBinding(Entry.TextProperty, nameof(bindingContext.Quantity));
            Stepper quantityStepper = new Stepper();
            quantityStepper.SetBinding(Stepper.ValueProperty, nameof(bindingContext.Quantity));
            #endregion

            #region Rating
            Entry rating = new Entry()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand, HorizontalTextAlignment = TextAlignment.End
            };
            rating.SetBinding(Entry.TextProperty, nameof(bindingContext.Rating));
            Slider ratingSlider = new Slider()
            {
                Minimum = 0, Maximum = 10
            };
            ratingSlider.SetBinding(Slider.ValueProperty, nameof(bindingContext.Rating));
            ratingSlider.HorizontalOptions = LayoutOptions.FillAndExpand;
            #endregion

            #region Comment
            Editor comment = new Editor();
            comment.SetBinding(Editor.TextProperty, nameof(bindingContext.Comment));
            comment.HorizontalOptions = LayoutOptions.FillAndExpand;
            comment.VerticalOptions   = LayoutOptions.FillAndExpand;
            #endregion

            #region Add controls to the Table Section
            tableView.Root.Add(new TableSection("Intervista")
            {
                isInterested,
                new ViewCell()
                {
                    View = new StackLayout()
                    {
                        Orientation = StackOrientation.Horizontal,
                        Padding     = new Thickness()
                        {
                            Left = paddingLeft
                        },
                        Children =
                        {
                            new Label()
                            {
                                Text = "Quantità",
                                HorizontalOptions = LayoutOptions.StartAndExpand,
                                VerticalOptions   = LayoutOptions.Center,
                            },
                            quantity,
                            quantityStepper
                        }
                    }
                },
                new ViewCell()
                {
                    View = new StackLayout()
                    {
                        Orientation = StackOrientation.Horizontal,
                        Padding     = new Thickness()
                        {
                            Left = paddingLeft
                        },
                        Children =
                        {
                            new Label()
                            {
                                Text = "Valutazione",
                                HorizontalOptions = LayoutOptions.StartAndExpand,
                                VerticalOptions   = LayoutOptions.Center,
                            },
                            rating,
                            ratingSlider
                        }
                    }
                },
                new ViewCell()
                {
                    View = new StackLayout()
                    {
                        Orientation = StackOrientation.Horizontal,
                        Padding     = new Thickness()
                        {
                            Left = paddingLeft
                        },
                        Children =
                        {
                            new Label()
                            {
                                Text = "Commento",
                                HorizontalOptions = LayoutOptions.Start,
                                VerticalOptions   = LayoutOptions.Center,
                            },
                            comment
                        }
                    }
                }
            });
            #endregion

            #endregion

            #region Addresses
            //List<AddressViewCell> addressViewsList = new List<AddressViewCell>();
            //TableSection addressesTableSection = new TableSection("Indirizzi");
            //foreach (AddressModel addressModel in bindingContext.AddressesList)
            //{
            //    addressesTableSection.Add(new AddressViewCell() { BindingContext = addressModel });
            //}
            //tableView.Root.Add(addressesTableSection);

            Button btnAddAddress = new Button()
            {
                Text = "Aggiungi indirizzo"
            };
            btnAddAddress.Clicked += BtnAddAddress_Clicked;
            //stackLayout.Children.Add(btnAddAddress);

            ListView addressesViews = new ListView();
            addressesViews.SetBinding(ListView.ItemsSourceProperty, nameof(bindingContext.AddressesList));
            addressesViews.ItemTemplate = new DataTemplate(typeof(AddressViewCell));
            addressesViews.RowHeight    = 200;
            //stackLayout.Children.Add(addressesViews);

            tableView.Root.Add(new TableSection("Indirizzi")
            {
                new ViewCell()
                {
                    View = btnAddAddress
                },
                new ViewCell()
                {
                    View = addressesViews
                }
            });
            #endregion

            stackLayout.Children.Add(tableView);
        }
Example #10
0
        public SettingsPage(Coach coach)
        {
            this.coach = coach;

            Title = NavTitle = "Instellingen";
            //Icon = "settings.png";
            Icon = "icon";

            var tpStyles = StyleKit.AutoDarkStyles <TimePicker>();

            var moodMonitor  = coach.Monitors.Where(m => m is MoodMonitor).First();
            var morningCheck = new TimePicker {
                BindingContext = moodMonitor,
                Format         = "HH:mm",
                Style          = tpStyles.Body
            };

            morningCheck.SetBinding(TimePicker.TimeProperty, "MorningCheck", BindingMode.TwoWay);
            var eveningCheck = new TimePicker {
                BindingContext = moodMonitor,
                Format         = "HH:mm",
                Style          = tpStyles.Body
            };

            eveningCheck.SetBinding(TimePicker.TimeProperty, "EveningCheck", BindingMode.TwoWay);

            var activityMonitor = coach.Monitors.Where(m => m is ActivityMonitor).First();
            var activityCheck   = new TimePicker {
                BindingContext = activityMonitor,
                Format         = "HH:mm",
                Style          = tpStyles.Body
            };

            activityCheck.SetBinding(TimePicker.TimeProperty, "Check", BindingMode.TwoWay);

            Label exportLabel;
            var   exportCell = new ViewCell {
                View = new StackLayout {
                    Orientation = StackOrientation.Horizontal,
                    Padding     = new Thickness(15, 5),
                    Children    =
                    {
                        (exportLabel              = new Label {
                            Text                  = "Exporteer gebruikersprofiel",
#if __ANDROID__
                            TextColor             = Color.Black,
#endif
                            VerticalTextAlignment = TextAlignment.Center,
                            Style                 = StyleKit.AutoDarkLabelStyles.Body
                        })
                    }
                },
                StyleId = "disclosure"
            };

            exportCell.Tapped += (sender, e) => {
                MessagingCenter.Send <View, string>(exportLabel, "Share", coach.UserProfile.Serialize(coach));
            };

            Content = new TableView {
                Root = new TableRoot {
                    new TableSection("Tijden stemmingscheck")
                    {
                        new ViewCell {
                            View = new StackLayout {
                                Orientation = StackOrientation.Horizontal,
                                Padding     = new Thickness(15, 5),
                                Children    =
                                {
                                    new Label {
                                        Text = "'s Ochtends om: ",
#if __ANDROID__
                                        TextColor = Color.Black,
#endif
                                        VerticalTextAlignment = TextAlignment.Center,
                                        Style = StyleKit.AutoDarkLabelStyles.Body
                                    },
                                    morningCheck
                                }
                            }
                        },
                        new ViewCell {
                            View = new StackLayout {
                                Orientation = StackOrientation.Horizontal,
                                Padding     = new Thickness(15, 5),
                                Children    =
                                {
                                    new Label {
                                        Text = "'s Avonds om: ",
#if __ANDROID__
                                        TextColor = Color.Black,
#endif
                                        VerticalTextAlignment = TextAlignment.Center,
                                        Style = StyleKit.AutoDarkLabelStyles.Body
                                    },
                                    eveningCheck
                                }
                            }
                        },
                    },
                    new TableSection("Tijd dagevaluatie")
                    {
                        new ViewCell {
                            View = new StackLayout {
                                Orientation = StackOrientation.Horizontal,
                                Padding     = new Thickness(15, 5),
                                Children    =
                                {
                                    new Label {
                                        Text = "'s Avonds om: ",
#if __ANDROID__
                                        TextColor = Color.Black,
#endif
                                        VerticalTextAlignment = TextAlignment.Center,
                                        Style = StyleKit.AutoDarkLabelStyles.Body
                                    },
                                    activityCheck
                                }
                            }
                        },
                    },


                    new TableSection("Toegangsinstellingen")
                    {
                        new TextCell {
                            Text = "Pincode opnieuw instellen",
#if __ANDROID__
                            TextColor = Color.Black,
#endif

                            Command = new Command(async() => {
                                await Navigation.PushAsync(new PasswordPage(coach));
                            }),
                            StyleId = "disclosure"
                        },
                        new TextCell {
                            Text      = "Emailadres opnieuw instellen",
                            TextColor = Color.Black,

                            Command = new Command(async() => {
                                await Navigation.PushAsync(new EmailPage(coach));
                            }),
                            StyleId = "disclosure"
                        },
                    },
                    new TableSection("Geavanceerd")
                    {
                        exportCell,
                        //new TextCell {
                        //    Text = "Forceer nieuwe tip",
                        //    Command = new Command(async () => {
                        //        coach.Scheduler.ForceNextTip();
                        //        await Alert.Show(
                        //            "Nieuwe tip",
                        //            "Er staat een nieuwe tip voor u klaar!",
                        //            null,
                        //            new AlertButton
                        //            {
                        //                Text = "Later",
                        //                Action = () => false
                        //            },
                        //            new AlertButton
                        //            {
                        //                Text = "Naar tip",
                        //                IsPreferred = true,
                        //                Action = () => {
                        //                    Navigation.PushAsync(new TipPage(coach, "Nieuwe tip"));
                        //                    return false;
                        //                }
                        //            }
                        //        );
                        //    })
                        //},
                        //new TextCell {
                        //    Text = "Test stemmingscheck",
                        //    Command = new Command(async () => {
                        //        var monitor = new MoodMonitor(coach.UserProfile);
                        //        await monitor.Perform();
                        //    })
                        //},
                        //new TextCell {
                        //    Text = "Test dagevaluatie",
                        //    Command = new Command(async () => {
                        //        var monitor = new ActivityMonitor(coach.UserProfile);
                        //        await monitor.Perform();
                        //    })
                        //},
                    }
                },
                Intent = TableIntent.Settings
            };
        }
Example #11
0
        public MainView()
            : base(new BabysitterViewModel())
        {
            Title = "Babysitter Calculator";
            Entry txtStartToBedRate = new Entry {
                Keyboard = Keyboard.Numeric, Placeholder = "Start to bed rate"
            };
            Entry txtBedToMidnightRate = new Entry {
                Keyboard = Keyboard.Numeric, Placeholder = "Bed to midnight rate"
            };
            Entry txtMidnightToEndRate = new Entry {
                Keyboard = Keyboard.Numeric, Placeholder = "Midnight to end rate"
            };

            txtStartToBedRate.SetBinding <BabysitterViewModel>(Entry.TextProperty, vm => vm.StartToBedRate);
            txtBedToMidnightRate.SetBinding <BabysitterViewModel>(Entry.TextProperty, vm => vm.BedToMidnightRate);
            txtMidnightToEndRate.SetBinding <BabysitterViewModel>(Entry.TextProperty, vm => vm.MidnightToEndRate);
            DatePicker shiftDate = new DatePicker();
            TimePicker start     = new TimePicker();
            TimePicker end       = new TimePicker();
            TimePicker bedTime   = new TimePicker();

            shiftDate.SetBinding <BabysitterViewModel>(DatePicker.DateProperty, vm => vm.ShiftDate);
            start.SetBinding <BabysitterViewModel>(TimePicker.TimeProperty, vm => vm.Start);
            end.SetBinding <BabysitterViewModel>(TimePicker.TimeProperty, vm => vm.End);
            bedTime.SetBinding <BabysitterViewModel>(TimePicker.TimeProperty, vm => vm.BedTime);
            Label lblTotal = new Label {
                FontSize = 24
            };

            lblTotal.SetBinding <BabysitterViewModel>(Label.TextProperty, vm => vm.Total);
            Button btnCalc = new Button {
                Text = "Calculate"
            };

            btnCalc.SetBinding <BabysitterViewModel>(Button.CommandProperty, mv => mv.CmdCalc);
            Content = new StackLayout
            {
                Children =
                {
                    new ScrollView
                    {
                        Content = new StackLayout
                        {
                            Children =
                            {
                                new Label {
                                    Text = "Start to bed rate"
                                },
                                txtStartToBedRate,
                                new Label {
                                    Text = "Bed to midnight rate"
                                },
                                txtBedToMidnightRate,
                                new Label {
                                    Text = "Midnight to end rate"
                                },
                                txtMidnightToEndRate,
                                new Label {
                                    Text = "Shift date"
                                },
                                shiftDate,
                                new Label {
                                    Text = "Start time"
                                },
                                start,
                                new Label {
                                    Text = "End time"
                                },
                                end,
                                new Label {
                                    Text = "Bed time"
                                },
                                bedTime,
                                new Label {
                                    Text = "Total"
                                },
                                lblTotal,
                            }
                        }
                    },
                    btnCalc
                }
            };
        }
Example #12
0
        private void RenderEditItemField(Item item, Field field)
        {
            // skip rendering a hidden field
            if (field.DisplayType == DisplayTypes.Hidden)
                return;

            PropertyInfo pi = null;
            object currentValue = null;
            object container = null;

            // get the current field value.
            // the value can either be in a strongly-typed property on the item (e.g. Name),
            // or in one of the FieldValues
            try
            {
                // get the strongly typed property
                pi = item.GetType().GetProperty(field.Name);
                if (pi != null)
                {
                    // store current item's value for this field
                    currentValue = pi.GetValue(item, null);

                    // set the container - this will be the object that will be passed
                    // to pi.SetValue() below to poke new values into
                    container = itemCopy;
                }
            }
            catch (Exception)
            {
                // an exception indicates this isn't a strongly typed property on the Item
                // this is NOT an error condition
            }

            // if couldn't find a strongly typed property, this property is stored as a
            // FieldValue on the item
            if (pi == null)
            {
                // get current item's value for this field, or create a new FieldValue
                // if one doesn't already exist
                FieldValue fieldValue = item.GetFieldValue(field.ID, true);
                currentValue = fieldValue.Value;

                // get the value property of the current fieldvalue (this should never fail)
                pi = fieldValue.GetType().GetProperty("Value");
                if (pi == null)
                    return;

                // set the container - this will be the object that will be passed
                // to pi.SetValue() below to poke new values into
                container = fieldValue;
            }

            ListBoxItem listBoxItem = new ListBoxItem();
            StackPanel EditStackPanel = new StackPanel();
            listBoxItem.Content = EditStackPanel;
            EditStackPanel.Children.Add(
                new TextBlock()
                {
                    Text = field.DisplayName,
                    Style = (Style)App.Current.Resources["PhoneTextNormalStyle"]
                });

            // create a textbox (will be used by the majority of field types)
            double minWidth = App.Current.RootVisual.RenderSize.Width;
            if ((int)minWidth == 0)
                minWidth = ((this.Orientation & PageOrientation.Portrait) == PageOrientation.Portrait) ? 480.0 : 800.0;

            TextBox tb = new TextBox() { DataContext = container, MinWidth = minWidth, IsTabStop = true };
            tb.SetBinding(TextBox.TextProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });

            bool notMatched = false;
            // render the right control based on the DisplayType
            switch (field.DisplayType)
            {
                case DisplayTypes.Text:
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    EditStackPanel.Children.Add(tb);
                    break;
                case DisplayTypes.TextArea:
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
                    tb.AcceptsReturn = true;
                    tb.TextWrapping = TextWrapping.Wrap;
                    tb.Height = 150;
                    tb.TabIndex = tabIndex++;
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
                    EditStackPanel.Children.Add(tb);
                    break;
                case DisplayTypes.Phone:
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.TelephoneNumber } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.MinWidth -= 64;
                    tb.MaxWidth = tb.MinWidth;
                    StackPanel innerPanel = RenderImageButtonPanel(tb);
                    ImageButton imageButton = (ImageButton)innerPanel.Children[1];
                    imageButton.Click += new RoutedEventHandler(delegate
                    {
                        PhoneNumberChooserTask chooser = new PhoneNumberChooserTask();
                        chooser.Completed += new EventHandler<PhoneNumberResult>((sender, e) =>
                        {
                            if (e.TaskResult == TaskResult.OK && e.PhoneNumber != null && e.PhoneNumber != "")
                                pi.SetValue(container, e.PhoneNumber, null);
                        });
                        chooser.Show();
                    });
                    EditStackPanel.Children.Add(innerPanel);
                    break;
                case DisplayTypes.Link:
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Url } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    EditStackPanel.Children.Add(tb);
                    break;
                case DisplayTypes.Email:
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.EmailSmtpAddress } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    tb.MinWidth -= 64;
                    tb.MaxWidth = tb.MinWidth;
                    innerPanel = RenderImageButtonPanel(tb);
                    imageButton = (ImageButton)innerPanel.Children[1];
                    imageButton.Click += new RoutedEventHandler(delegate
                    {
                        EmailAddressChooserTask chooser = new EmailAddressChooserTask();
                        chooser.Completed += new EventHandler<EmailResult>((s, e) =>
                        {
                            if (e.TaskResult == TaskResult.OK && !String.IsNullOrEmpty(e.Email))
                            {
                                pi.SetValue(container, e.Email, null);
                                // find the contact using the email address
                                Contacts contacts = new Contacts();
                                contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>((sen, ev) =>
                                {
                                    // save the contact info as a new contact
                                    var contact = ev.Results.FirstOrDefault();
                                    if (contact == null)
                                        return;
                                    ContactPickerHelper.AddContactInfo(contact, item);
                                });
                                contacts.SearchAsync(e.Email, FilterKind.EmailAddress, null);
                            }
                        });
                        chooser.Show();
                    });
                    EditStackPanel.Children.Add(innerPanel);
                    break;
                case DisplayTypes.Address:
                    tb.InputScope = new InputScope()
                    {
                        Names =
                            {
                                new InputScopeName() { NameValue = InputScopeNameValue.AddressStreet },
                                new InputScopeName() { NameValue = InputScopeNameValue.AddressCity },
                                new InputScopeName() { NameValue = InputScopeNameValue.AddressStateOrProvince },
                                new InputScopeName() { NameValue = InputScopeNameValue.AddressCountryName },
                            }
                    };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    tb.MinWidth -= 64;
                    tb.MaxWidth = tb.MinWidth;
                    innerPanel = RenderImageButtonPanel(tb);
                    imageButton = (ImageButton)innerPanel.Children[1];
                    imageButton.Click += new RoutedEventHandler(delegate
                    {
                        // start the location service
                        GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
                        watcher.MovementThreshold = 20; // Use MovementThreshold to ignore noise in the signal.
                        watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>((sender, e) =>
                        {
                            if (e.Status == GeoPositionStatus.Ready)
                            {
                                // Use the Position property of the GeoCoordinateWatcher object to get the current location.
                                GeoCoordinate co = watcher.Position.Location;
                                tb.Text = co.Latitude.ToString("0.000") + "," + co.Longitude.ToString("0.000");
                                // Stop the Location Service to conserve battery power.
                                watcher.Stop();
                                // also store the latlong information in a hidden LatLong FieldValue
                                var latlong = item.GetFieldValue(FieldNames.LatLong, true);
                                if (latlong != null)
                                    latlong.Value = tb.Text;
                            }
                        });
                        watcher.Start();
                    });
                    EditStackPanel.Children.Add(innerPanel);
                    break;
                case DisplayTypes.Priority:
                    ListPicker lp = new ListPicker()
                    {
                        MinWidth = minWidth,
                        FullModeItemTemplate = (DataTemplate)App.Current.Resources["FullListPickerTemplate"],
                        IsTabStop = true
                    };
                    lp.ItemsSource = App.ViewModel.Constants.Priorities;
                    lp.DisplayMemberPath = "Name";
                    int? lpval = (int?)pi.GetValue(container, null);
                    if (lpval != null)
                        lp.SelectedIndex = (int)lpval;
                    else
                        lp.SelectedIndex = 1;  // HACK: hardcode to "Normal" priority.  this should come from a table.
                    lp.SelectionChanged += new SelectionChangedEventHandler(delegate { pi.SetValue(container, lp.SelectedIndex == 1 ? (int?)null : lp.SelectedIndex, null); });
                    lp.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(lp);
                    break;
                case DisplayTypes.Folders:
                    ListPicker folderPicker = new ListPicker() { MinWidth = minWidth, IsTabStop = true };
                    folderPicker.ItemsSource = App.ViewModel.Folders;
                    folderPicker.DisplayMemberPath = "Name";
                    Folder tl = App.ViewModel.Folders.FirstOrDefault(list => list.ID == folder.ID);
                    folderPicker.SelectedIndex = App.ViewModel.Folders.IndexOf(tl);
                    folderPicker.SelectionChanged += new SelectionChangedEventHandler(delegate { pi.SetValue(container, App.ViewModel.Folders[folderPicker.SelectedIndex].ID, null); });
                    folderPicker.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(folderPicker);
                    break;
                case DisplayTypes.Lists:
                    ListPicker listPicker = new ListPicker()
                    {
                        MinWidth = minWidth,
                        FullModeItemTemplate = (DataTemplate)App.Current.Resources["FullListPickerTemplate"],
                        ExpansionMode = ExpansionMode.FullScreenOnly,
                        IsTabStop = true
                    };
                    var lists = App.ViewModel.Items.
                        Where(i => i.FolderID == item.FolderID && i.IsList == true && i.ItemTypeID != SystemItemTypes.Reference).
                        OrderBy(i => i.Name).
                        ToObservableCollection();
                    lists.Insert(0, new Item()
                    {
                        ID = Guid.Empty,
                        Name = folder.Name + " (folder)"
                    });
                    listPicker.ItemsSource = lists;
                    listPicker.DisplayMemberPath = "Name";
                    var listGuid = currentValue != null ? (Guid) currentValue : Guid.Empty;
                    Item thisItem = lists.FirstOrDefault(i => i.ID == (Guid) listGuid);
                    // if the list isn't found (e.g. ParentID == null), SelectedIndex will default to the Folder scope (which is correct for that case)
                    listPicker.SelectedIndex = Math.Max(lists.IndexOf(thisItem), 0);
                    listPicker.SelectionChanged += new SelectionChangedEventHandler(delegate { pi.SetValue(container, lists[listPicker.SelectedIndex].ID, null); });
                    listPicker.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(listPicker);
                    break;
                case DisplayTypes.DatePicker:
                    DatePicker dp = new DatePicker() { DataContext = container, MinWidth = minWidth, IsTabStop = true };
                    DateTime date = Convert.ToDateTime((string)currentValue);
                    if (date.Ticks == 0)
                        date = DateTime.Now.Date;
                    dp.Value = date;
                    dp.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(delegate
                    {
                        //pi.SetValue(container, dp.Value, null);
                        pi.SetValue(container, dp.Value == null ? null : ((DateTime)dp.Value).ToString("d"), null);
                        folder.NotifyPropertyChanged("FirstDue");
                        folder.NotifyPropertyChanged("FirstDueColor");
                    });
                    dp.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(dp);
                    break;
                case DisplayTypes.DateTimePicker:
                    // create date picker
                    DatePicker datePicker = new DatePicker() { DataContext = container, MinWidth = minWidth, IsTabStop = true };
                    // set up two-way data binding so that we don't have to pick up the new value in the event handler
                    datePicker.SetBinding(DatePicker.ValueProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                    datePicker.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(delegate
                    {
                        folder.NotifyPropertyChanged("FirstDue");
                        folder.NotifyPropertyChanged("FirstDueColor");
                    });
                    datePicker.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(datePicker);
                    // create time picker
                    TimePicker timePicker = new TimePicker() { DataContext = container, MinWidth = minWidth, IsTabStop = true };
                    // set up two-way data binding so that we don't have to pick up the new value in the event handler
                    timePicker.SetBinding(TimePicker.ValueProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                    timePicker.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(delegate
                    {
                        folder.NotifyPropertyChanged("FirstDue");
                        folder.NotifyPropertyChanged("FirstDueColor");
                    });
                    timePicker.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(timePicker);
                    break;
                case DisplayTypes.Checkbox:
                    CheckBox cb = new CheckBox() { DataContext = container, IsTabStop = true };
                    cb.SetBinding(CheckBox.IsCheckedProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                    cb.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(cb);
                    break;
                case DisplayTypes.TagList:
                    TextBox taglist = new TextBox() { MinWidth = minWidth, IsTabStop = true };
                    taglist.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    taglist.TabIndex = tabIndex++;
                    RenderEditItemTagList(taglist, (Item) container, pi);
                    EditStackPanel.Children.Add(taglist);
                    break;
                case DisplayTypes.ImageUrl:
                    // TODO: wire up to picture picker, and upload to an image service
                    break;
                case DisplayTypes.LinkArray:
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Url } } };
                    tb.AcceptsReturn = true;
                    tb.TextWrapping = TextWrapping.Wrap;
                    tb.Height = 150;
                    tb.TabIndex = tabIndex++;
                    tb.ClearValue(TextBox.TextProperty);
                    if (!String.IsNullOrEmpty((string) currentValue))
                    {
                        try
                        {
                            var linkList = JsonConvert.DeserializeObject<List<Link>>((string)currentValue);
                            tb.Text = String.Concat(linkList.Select(l => l.Name != null ? l.Name + "," + l.Url + "\n" : l.Url + "\n").ToList());
                        }
                        catch (Exception)
                        {
                        }
                    }
                    tb.LostFocus += new RoutedEventHandler(delegate
                    {
                        // the expected format is a newline-delimited list of Name, Url pairs
                        var linkArray = tb.Text.Split(new char[] { '\r','\n' }, StringSplitOptions.RemoveEmptyEntries);
                        var linkList = new List<Link>();
                        foreach (var link in linkArray)
                        {
                            var nameval = link.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            if (nameval.Length == 0)
                                continue;
                            if (nameval.Length == 1)
                                linkList.Add(new Link() { Url = nameval[0].Trim() });
                            else
                                linkList.Add(new Link() { Name = nameval[0].Trim(), Url = nameval[1].Trim() });
                        }
                        var json = JsonConvert.SerializeObject(linkList);
                        pi.SetValue(container, json, null);
                    });
                    EditStackPanel.Children.Add(tb);
                    break;
                case DisplayTypes.Hidden:
                    // skip rendering
                    break;
                case DisplayTypes.ContactList:
                    Item currentContacts = CreateValueList(item, field, currentValue == null ? Guid.Empty : new Guid((string) currentValue));
                    var contactPicker = new ItemRefListPicker(folder, currentContacts, SystemItemTypes.Contact, pi, container)
                    {
                        MinWidth = minWidth,
                        IsTabStop = true
                    };
                    contactPicker.TabIndex = tabIndex++;
                    contactPicker.MinWidth -= 84;
                    contactPicker.MaxWidth = contactPicker.MinWidth;
                    innerPanel = RenderImageButtonPanel(contactPicker, "/Images/button.add.png", "/Images/button.add.pressed.png");
                    imageButton = (ImageButton)innerPanel.Children[1];
                    imageButton.Click += new RoutedEventHandler(delegate
                    {
                        EmailAddressChooserTask chooser = new EmailAddressChooserTask();
                        chooser.Completed += new EventHandler<EmailResult>((s, e) =>
                        {
                            if (e.TaskResult == TaskResult.OK && !String.IsNullOrEmpty(e.Email))
                            {
                                // find the contact using the email address
                                Contacts contacts = new Contacts();
                                contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>((sen, ev) =>
                                {
                                    // save the contact info as a new contact
                                    var contact = ev.Results.FirstOrDefault();
                                    if (contact == null)
                                        return;
                                    var newContact = ContactPickerHelper.ProcessContact(contact);
                                    if (newContact != null)
                                    {
                                        // if the list doesn't yet exist, create it now
                                        if (currentContacts.ID == Guid.Empty)
                                        {
                                            Guid id = Guid.NewGuid();
                                            currentContacts.ID = id;

                                            // enqueue the Web Request Record
                                            RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                                                new RequestQueue.RequestRecord()
                                                {
                                                    ReqType = RequestQueue.RequestRecord.RequestType.Insert,
                                                    Body = currentContacts
                                                });

                                            // add the list to the folder
                                            folder.Items.Add(currentContacts);
                                            StorageHelper.WriteFolder(folder);

                                            // store the list's Guid in the item's property
                                            pi.SetValue(container, id.ToString(), null);
                                        }

                                        // rebuild the image panel with a new ItemRefListPicker
                                        HandleAddedContact(currentContacts, newContact);
                                        var oldListPicker = innerPanel.Children[0] as ItemRefListPicker;
                                        contactPicker = new ItemRefListPicker(folder, currentContacts, SystemItemTypes.Contact, pi, container)
                                        {
                                            IsTabStop = true
                                        };
                                        if (oldListPicker != null)
                                        {
                                            contactPicker.TabIndex = oldListPicker.TabIndex;
                                            contactPicker.MinWidth = oldListPicker.MinWidth;
                                            contactPicker.MaxWidth = oldListPicker.MaxWidth;
                                        }
                                        innerPanel.Children[0] = contactPicker;
                                    }
                                });
                                contacts.SearchAsync(e.Email, FilterKind.EmailAddress, null);
                            }
                        });
                        chooser.Show();
                    });
                    EditStackPanel.Children.Add(innerPanel);
                    break;
                case DisplayTypes.LocationList:
                    Item currentLocations = CreateValueList(item, field, currentValue == null ? Guid.Empty : new Guid((string) currentValue));
                    var locationPicker = new ItemRefListPicker(folder, currentLocations, SystemItemTypes.Location, pi, container)
                    {
                        MinWidth = minWidth,
                        IsTabStop = true
                    };
                    locationPicker.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(locationPicker);
                    break;
                case DisplayTypes.ItemTypes:
                    ListPicker itemTypePicker = new ListPicker()
                    {
                        MinWidth = minWidth,
                        FullModeItemTemplate = (DataTemplate)App.Current.Resources["FullListPickerTemplate"],
                        ExpansionMode = ExpansionMode.FullScreenOnly,
                        IsTabStop = true
                    };
                    var itemTypes = App.ViewModel.ItemTypes.Where(i => i.UserID != SystemUsers.System).OrderBy(i => i.Name).ToList();
                    itemTypePicker.ItemsSource = itemTypes;
                    itemTypePicker.DisplayMemberPath = "Name";
                    ItemType thisItemType = itemTypes.FirstOrDefault(i => i.ID == (Guid) currentValue);
                    itemTypePicker.SelectedIndex = Math.Max(itemTypes.IndexOf(thisItemType), 0);
                    itemTypePicker.SelectionChanged += new SelectionChangedEventHandler(delegate { pi.SetValue(container, itemTypes[itemTypePicker.SelectedIndex].ID, null); });
                    itemTypePicker.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(itemTypePicker);
                    break;
                default:
                    notMatched = true;
                    break;
            }

            // if wasn't able to match field type by display type, try matching by FieldType
            if (notMatched == true)
            {
                switch (field.FieldType)
                {
                    case FieldTypes.String:
                    default:
                        tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
                        tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, tb.Text, null); });
                        tb.TabIndex = tabIndex++;
                        tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                        EditStackPanel.Children.Add(tb);
                        break;
                    case FieldTypes.Integer:
                        tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Digits } } };
                        tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(container, Convert.ToInt32(tb.Text), null); });
                        tb.TabIndex = tabIndex++;
                        tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                        EditStackPanel.Children.Add(tb);
                        break;
                    case FieldTypes.DateTime:
                        DatePicker dp = new DatePicker() { DataContext = container, MinWidth = minWidth, IsTabStop = true };
                        dp.SetBinding(DatePicker.ValueProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                        dp.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(delegate
                        {
                            pi.SetValue(container, dp.Value, null);
                            folder.NotifyPropertyChanged("FirstDue");
                            folder.NotifyPropertyChanged("FirstDueColor");
                        });
                        dp.TabIndex = tabIndex++;
                        EditStackPanel.Children.Add(dp);
                        break;
                    case FieldTypes.Boolean:
                        CheckBox cb = new CheckBox() { DataContext = container, IsTabStop = true };
                        cb.SetBinding(CheckBox.IsEnabledProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                        cb.TabIndex = tabIndex++;
                        EditStackPanel.Children.Add(cb);
                        break;
                }
            }

            // add the listboxitem to the listbox
            EditListBox.Items.Add(listBoxItem);
        }
Example #13
0
        private DataTemplate CreateTimerSelectedItemTemplate()
        {
            DataTemplate template = new DataTemplate(() =>
            {
                var grid           = new Grid();
                grid.HeightRequest = 300;
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Auto)
                });
                grid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Auto)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Auto)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Auto)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.25, GridUnitType.Auto)
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(0.25, GridUnitType.Auto)
                });
                var nameLabel = new Label {
                    FontAttributes = FontAttributes.Bold
                };
                var durationLabel    = new Label();
                var repetitionsLabel = new Label {
                    HorizontalTextAlignment = TextAlignment.End
                };
                var nameEntry = new Entry()
                {
                    Placeholder = "Name"
                };
                var durationPicker           = new TimePicker();
                var increaseRepetitionButton = new Button()
                {
                    Text = "+"
                };
                var decreaseRepetitionButton = new Button()
                {
                    Text = "-"
                };

                nameLabel.SetBinding(Label.TextProperty, "Name");
                nameEntry.SetBinding(Entry.TextProperty, "Name");
                durationLabel.SetBinding(Label.TextProperty, "DurationText");
                repetitionsLabel.SetBinding(Label.TextProperty, "RepetitionsText");

                durationPicker.SetBinding(TimePicker.TimeProperty, "Duration", BindingMode.OneWayToSource);
                durationPicker.PropertyChanged += DurationPicker_PropertyChanged;

                grid.Children.Add(nameLabel);
                grid.Children.Add(durationLabel, 1, 0);
                grid.Children.Add(repetitionsLabel, 2, 0);
                grid.Children.Add(nameEntry, 0, 1);
                grid.Children.Add(durationPicker, 1, 1);
                grid.Children.Add(increaseRepetitionButton, 2, 1);
                grid.Children.Add(decreaseRepetitionButton, 3, 1);

                increaseRepetitionButton.Clicked += IncreaseRepetitionButton_Clicked;
                decreaseRepetitionButton.Clicked += DecreaseRepetitionButton_Clicked;
                return(new ViewCell {
                    View = grid
                });
            });

            return(template);
        }
        private void InitialiseElements()
        {
            Label labelTitle = new Label()
            {
                Text       = "Edit",
                FontSize   = 24,
                FontFamily = "Roboto",
                TextColor  = Constants.TextColor,
                HorizontalTextAlignment = TextAlignment.Center
            };

            Label labelStarted = new Label()
            {
                Text       = "Started",
                FontSize   = 24,
                FontFamily = "Roboto",
                TextColor  = Constants.TextColor,
                HorizontalTextAlignment = TextAlignment.Start
            };

            Label labelEnded = new Label()
            {
                Text       = "Ended",
                FontSize   = 24,
                FontFamily = "Roboto",
                TextColor  = Constants.TextColor,
                HorizontalTextAlignment = TextAlignment.Start
            };

            labelEnded.SetBinding(Label.IsVisibleProperty, "EndPickersVisible");

            ImageButton btnBackArrow = new ImageButton()
            {
                Source = "backarrow.png",
                Aspect = Aspect.Fill
            };

            btnBackArrow.SetBinding(ImageButton.TappedCommandProperty, "BackButtonCommand");

            ImageButton btnAccept = new ImageButton()
            {
                Aspect = Aspect.Fill
            };

            btnAccept.SetBinding(ImageButton.SourceProperty, "AcceptButtonImage");
            btnAccept.SetBinding(ImageButton.TappedCommandProperty, "AcceptButtonCommand");
            btnAccept.SetBinding(ImageButton.IsEnabledProperty, "AcceptButtonEnabled", BindingMode.TwoWay);

            ImageButton btnDelete = new ImageButton()
            {
                Source = "deletebtn.png",
                Aspect = Aspect.Fill
            };

            btnDelete.SetBinding(ImageButton.TappedCommandProperty, "DeleteButtonCommand");
            btnDelete.SetBinding(ImageButton.IsEnabledProperty, "DeleteButtonEnabled", BindingMode.TwoWay);

            DatePicker dpStartDate = new DatePicker()
            {
                Format    = Constants.DateFormat,
                TextColor = Constants.TextColor
            };

            dpStartDate.SetBinding(DatePicker.DateProperty, "StartDate", BindingMode.TwoWay);
            dpStartDate.SetBinding(DatePicker.MaximumDateProperty, "MaximumStartDate");

            TimePicker tpStartTime = new TimePicker()
            {
                Format    = Constants.TimeSecondsFormat,
                TextColor = Constants.TextColor
            };

            tpStartTime.SetBinding(TimePicker.TimeProperty, "StartTime", BindingMode.TwoWay);

            DatePicker dpEndDate = new DatePicker()
            {
                Format    = Constants.DateFormat,
                TextColor = Constants.TextColor
            };

            dpEndDate.SetBinding(DatePicker.DateProperty, "EndDate", BindingMode.TwoWay);
            dpEndDate.SetBinding(DatePicker.MinimumDateProperty, "MinimumEndDate");
            dpEndDate.SetBinding(DatePicker.IsVisibleProperty, "EndPickersVisible");

            TimePicker tpEndTime = new TimePicker()
            {
                Format    = Constants.TimeSecondsFormat,
                TextColor = Constants.TextColor
            };

            tpEndTime.SetBinding(TimePicker.TimeProperty, "EndTime", BindingMode.TwoWay);
            tpEndTime.SetBinding(TimePicker.IsVisibleProperty, "EndPickersVisible");

            rl.AddView(btnBackArrow, Constraint.RelativeToParent((p) =>
            {
                return(p.X + 10);
            }),
                       Constraint.RelativeToParent((p) =>
            {
                return(p.Y + 10);
            }),
                       Constraint.Constant(32),
                       Constraint.Constant(32)
                       );

            rl.AddView(btnDelete, Constraint.RelativeToParent((p) =>
            {
                return(p.Width - 10 - 40);
            }),
                       Constraint.RelativeToParent((p) =>
            {
                return(p.Y + 10);
            }),
                       Constraint.Constant(40),
                       Constraint.Constant(40)
                       );

            rl.AddView(labelTitle, Constraint.RelativeToParent((p) =>
            {
                return(p.X);
            }),
                       Constraint.RelativeToParent((p) =>
            {
                return(p.Y + 55);
            }),
                       Constraint.RelativeToParent((p) =>
            {
                return(p.Width);
            }),
                       Constraint.Constant(32)
                       );

            int indent = 42;

            rl.AddView(labelStarted, Constraint.RelativeToParent((p) =>
            {
                return(p.X + indent);
            }),
                       Constraint.RelativeToView(labelTitle, (p, s) =>
            {
                return(s.Y + s.Height + 120);
            }),
                       Constraint.Constant(150),
                       Constraint.Constant(32)
                       );

            int buffer = 10;
            int margin = 10;
            int height = 40;

            rl.AddView(dpStartDate, Constraint.RelativeToView(labelStarted, (p, s) =>
            {
                return(s.X);
            }),
                       Constraint.RelativeToView(labelStarted, (p, s) =>
            {
                return(s.Y + s.Height + 10);
            }),
                       Constraint.RelativeToView(labelStarted, (p, s) =>
            {
                return(((p.Width - indent - margin) / 2) - buffer / 2);
            }),
                       Constraint.Constant(height)
                       );

            rl.AddView(tpStartTime, Constraint.RelativeToView(dpStartDate, (p, s) =>
            {
                return(s.X + s.Width + (buffer / 2));
            }),
                       Constraint.RelativeToView(dpStartDate, (p, s) =>
            {
                return(s.Y);
            }),
                       Constraint.RelativeToView(dpStartDate, (p, s) =>
            {
                return(s.Width);
            }),
                       Constraint.Constant(height)
                       );

            rl.AddView(labelEnded, Constraint.RelativeToParent((p) =>
            {
                return(p.X + indent);
            }),
                       Constraint.RelativeToView(labelStarted, (p, s) =>
            {
                return(s.Y + s.Height + 75);
            }),
                       Constraint.Constant(150),
                       Constraint.Constant(32)
                       );

            rl.AddView(dpEndDate, Constraint.RelativeToView(labelEnded, (p, s) =>
            {
                return(s.X);
            }),
                       Constraint.RelativeToView(labelEnded, (p, s) =>
            {
                return(s.Y + s.Height + 10);
            }),
                       Constraint.RelativeToView(labelEnded, (p, s) =>
            {
                return(((p.Width - indent - margin) / 2) - buffer / 2);
            }),
                       Constraint.Constant(height)
                       );

            rl.AddView(tpEndTime, Constraint.RelativeToView(dpEndDate, (p, s) =>
            {
                return(s.X + s.Width + (buffer / 2));
            }),
                       Constraint.RelativeToView(dpEndDate, (p, s) =>
            {
                return(s.Y);
            }),
                       Constraint.RelativeToView(dpEndDate, (p, s) =>
            {
                return(s.Width);
            }),
                       Constraint.Constant(height)
                       );

            int acceptBtnWidth  = 103;
            int acceptBtnHeight = 41;

            rl.AddView(btnAccept, Constraint.RelativeToParent((p) =>
            {
                return(p.Width / 2 - acceptBtnWidth / 2);
            }),
                       Constraint.RelativeToParent((p) =>
            {
                return(p.Height - acceptBtnHeight - 70);
            }),
                       Constraint.Constant(acceptBtnWidth),
                       Constraint.Constant(acceptBtnHeight)
                       );
        }
Example #15
0
        void CreateUI()
        {
            stack = new StackLayout
            {
                Orientation     = StackOrientation.Vertical,
                WidthRequest    = App.ScreenSize.Width,
                HeightRequest   = App.ScreenSize.Height - 48,
                VerticalOptions = LayoutOptions.StartAndExpand
            };

            innerStack = new StackLayout
            {
                VerticalOptions     = LayoutOptions.Start,
                HorizontalOptions   = LayoutOptions.Start,
                Orientation         = StackOrientation.Horizontal,
                MinimumWidthRequest = App.ScreenSize.Width,
                WidthRequest        = App.ScreenSize.Width,
                HeightRequest       = App.ScreenSize.Height - 48,
            };

            var topbar = new TopBar(true, "", this, 1, "back_arrow", "", innerStack, true).CreateTopBar();

            stack.HeightRequest = App.ScreenSize.Height - topbar.HeightRequest;

            var titleBar = new Label
            {
                WidthRequest            = App.ScreenSize.Width,
                HeightRequest           = 48,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                BackgroundColor         = FormsConstants.AppyLightBlue,
                TextColor = Color.White,
                Text      = Langs.Const_Button_Add_Odometer_Reading
            };

            var height = App.ScreenSize.Height - (48 * 2);
            var grid   = new Grid
            {
                WidthRequest   = App.ScreenSize.Width * .9,
                RowDefinitions = new RowDefinitionCollection
                {
                    new RowDefinition {
                        Height = height * .4
                    },
                    new RowDefinition {
                        Height = 1
                    },
                    new RowDefinition {
                        Height = GridLength.Star
                    },
                }
            };

            var addGrid = new Grid
            {
                WidthRequest      = App.ScreenSize.Width * .8,
                HeightRequest     = 48,
                BackgroundColor   = FormsConstants.AppyDarkBlue,
                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition {
                        Width = (App.ScreenSize.Width * .8) * .4
                    },
                    new ColumnDefinition {
                        Width = 1
                    },
                    new ColumnDefinition {
                        Width = GridLength.Star
                    }
                }
            };

            var enterOdo = UniversalEntry.GeneralEntryCell("", App.ScreenSize.Width * .8, Keyboard.Numeric, "XXXXX", ReturnKeyTypes.Done);

            enterOdo.SetBinding(Entry.TextProperty, new Binding("Reading"));

            addGrid.Children.Add(new Label {
                VerticalTextAlignment = TextAlignment.Center, FontSize = 16, TextColor = Color.White, FontFamily = Helper.RegFont, Text = Langs.Const_Label_Odometer
            }, 0, 0);
            addGrid.Children.Add(new BoxView {
                WidthRequest = 1, HeightRequest = 40, VerticalOptions = LayoutOptions.Center, BackgroundColor = Color.White
            }, 1, 0);
            addGrid.Children.Add(enterOdo, 2, 0);

            odoListView = new ListView
            {
                SeparatorVisibility = SeparatorVisibility.None,
                ItemsSource         = ViewModel.Readings,
                ItemTemplate        = new DataTemplate(typeof(OdoViewCell)),
                HasUnevenRows       = true
            };

            var datePicker = new DatePicker();

            datePicker.SetBinding(DatePicker.DateProperty, new Binding("DateAdded"));
            datePicker.SetBinding(DatePicker.IsVisibleProperty, new Binding("ShowDate"));
            datePicker.DateSelected += (s, e) => { ViewModel.DateAdded = e.NewDate; };
            var timePicker = new TimePicker();

            timePicker.SetBinding(TimePicker.TimeProperty, new Binding("TimeAdded"));
            timePicker.SetBinding(TimePicker.IsVisibleProperty, new Binding("ShowTime"));

            var btnDate = new Button
            {
                WidthRequest    = (App.ScreenSize.Width * .8) * .5,
                BackgroundColor = FormsConstants.AppyDarkShade,
                BorderRadius    = 6,
                Text            = Langs.Const_Label_Date,
                TextColor       = Color.White
            };

            btnDate.Clicked += delegate { datePicker.Focus(); };
            var btnTime = new Button
            {
                WidthRequest    = (App.ScreenSize.Width * .8) * .5,
                BackgroundColor = FormsConstants.AppyDarkShade,
                BorderRadius    = 6,
                Text            = Langs.Const_Button_Set_Time,
                TextColor       = Color.White
            };

            btnTime.Clicked += delegate { timePicker.Focus(); };

            var btnConfirm = new Button
            {
                WidthRequest = App.ScreenSize.Width * .8,
                BorderRadius = 8,
                TextColor    = Color.White,
                Text         = Langs.Const_Button_Add_Odometer_Reading
            };

            btnConfirm.Clicked += delegate { ViewModel.BtnAddOdometer.Execute(null); };

            grid.Children.Add(
                new StackLayout
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Padding           = new Thickness(0, 8),
                Children          =
                {
                    addGrid,
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    = { btnDate, btnTime }
                    },
                    btnConfirm
                }
            }, 0, 0);
            grid.Children.Add(new BoxView {
                HeightRequest = 1, WidthRequest = App.ScreenSize.Width, BackgroundColor = Color.White
            }, 0, 1);
            grid.Children.Add(odoListView, 0, 2);

            stack.Children.Add(grid);
            stack.Children.Add(odoListView);
            innerStack.Children.Add(stack);

            var masterStack = new StackLayout
            {
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Start,
                Children          =
                {
                    new StackLayout
                    {
                        VerticalOptions   = LayoutOptions.Start,
                        HorizontalOptions = LayoutOptions.Start,
                        WidthRequest      = App.ScreenSize.Width,
                        Children          = { topbar }
                    },
                    new StackLayout
                    {
                        TranslationY = -6,
                        Children     = { titleBar    }
                    },
                    innerStack
                }
            };

            Content = masterStack;
        }
Example #16
0
        private void CriarPagina()
        {
            /*var alturaTela = Height;
             * var paddingTela = alturaTela * .05f;
             * var alturaLogo = alturaTela * .5f;
             * var alturaMarginTopTextos = alturaTela * .1f;
             * var alguraTextos = alturaTela * .3f;*/

            //Padding = new Thickness(paddingTela);

            edtTitulo = new Entry
            {
                FontSize    = FONTE_TEXTOS,
                Placeholder = "Título:",
            };
            edtTitulo.SetBinding(Entry.TextProperty, "Titulo");

            edtDescricao = new Entry
            {
                FontSize    = FONTE_TEXTOS,
                Placeholder = "Descrição:",
            };
            edtDescricao.SetBinding(Entry.TextProperty, "Descricao");

            edtDetalhes = new Entry
            {
                FontSize    = FONTE_TEXTOS,
                Placeholder = "Detalhes:",
            };
            edtDetalhes.SetBinding(Entry.TextProperty, "Detalhes");

            dtpkLimite = new DatePicker {
            };
            dtpkLimite.SetBinding(DatePicker.DateProperty, "DataLimite");

            tmpkLimite = new TimePicker {
            };
            tmpkLimite.SetBinding(TimePicker.TimeProperty, "HoraLimite");


            var lblSwt = new Label
            {
                FontSize = FONTE_TEXTOS,
                Text     = "Concluído"
            };

            swtConcluido = new Switch {
            };
            swtConcluido.SetBinding(Switch.IsToggledProperty, "Completo");
            var swtContainer = new StackLayout {
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    lblSwt, swtConcluido
                }
            };

            var btnSave = new Button
            {
                Text = "Salvar",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BorderRadius      = 20,
                FontSize          = FONTE_TEXTOS,
            };

            btnSave.Clicked += BtnSave_Clicked;

            var btnRemove = new Button
            {
                Text = "Excluir",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BorderRadius      = 20,
                FontSize          = FONTE_TEXTOS,
                IsVisible         = ((Reminder)BindingContext).IdReminder != 0 // so mostra se for edicao
            };

            btnRemove.Clicked += BtnRemove_Clicked;;

            var containerBtn = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Padding           = new Thickness(40, 0),
                Children          =
                {
                    btnSave, btnRemove
                }
            };

            // set conteudo da página
            Content = new StackLayout
            {
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Spacing           = 20,
                Children          =
                {
                    edtTitulo, edtDescricao, edtDetalhes, swtContainer, dtpkLimite, tmpkLimite, containerBtn
                }
            };
        }
        public HistoryFilterPage()
        {
            BindingContext = new HistoryFilterViewModel();

            var maxDate = DateTime.Now;

            var rangeLabel = new TextCell()
            {
                IsEnabled = false
            };

            rangeLabel.SetBinding(TextCell.TextProperty, new Binding("TotalTimeSpan"));

            var startDatePicker = new DatePicker()
            {
                TextColor = Color.DimGray
            };

            startDatePicker.MaximumDate = maxDate;
            startDatePicker.SetBinding(DatePicker.DateProperty, new Binding("StartDate", BindingMode.TwoWay));

            var startTimePicker = new TimePicker()
            {
                TextColor = Color.DimGray
            };

            startTimePicker.SetBinding(TimePicker.TimeProperty, new Binding("StartTime", BindingMode.TwoWay));

            var endDatePicker = new DatePicker()
            {
                TextColor = Color.DimGray
            };

            endDatePicker.MaximumDate = maxDate;
            endDatePicker.SetBinding(DatePicker.DateProperty, new Binding("EndDate", BindingMode.TwoWay));

            var endTimePicker = new TimePicker()
            {
                TextColor = Color.DimGray
            };

            endTimePicker.SetBinding(TimePicker.TimeProperty, new Binding("EndTime", BindingMode.TwoWay));

            var uniqueMembersSwitch = new SwitchCell()
            {
                Text = "Unique Members Only"
            };

            uniqueMembersSwitch.SetBinding(SwitchCell.OnProperty, new Binding("UniqueMembersOnly", BindingMode.TwoWay));

            var allLocationsSwitch = new SwitchCell()
            {
                Text = "All Locations"
            };

            allLocationsSwitch.SetBinding(SwitchCell.OnProperty, new Binding("UseAllLocations", BindingMode.TwoWay));

            Content = new TableView
            {
                HasUnevenRows = true,
                Root          = new TableRoot {
                    new TableSection("Range")
                    {
                        rangeLabel
                    },
                    new TableSection("Filter")
                    {
                        new LabelledCustomViewCell("Start Date:", startDatePicker),
                        new LabelledCustomViewCell("Start Time:", startTimePicker),
                        new LabelledCustomViewCell("End Date:", endDatePicker),
                        new LabelledCustomViewCell("End Time:", endTimePicker),
                        uniqueMembersSwitch,
                        allLocationsSwitch
                    }
                },
                Intent = TableIntent.Settings
            };
        }