Example #1
0
        public void CreateField(DetailFormHelper helper, FieldData fieldData)
        {
            var text = fieldData as TextFieldData;
            int row;
            var textBlock  = helper.AddRow(text, out row);

            var textBox = new TextBox
            {
                TextWrapping = TextWrapping.Wrap,
                Text = DetailFormHelper.GetValueAsString(helper.DataElement, text.name, fieldData.defaultValue),
                Margin = new Thickness(5),
            };

            var lineHeight = Math.Max(1, text.lineHeight);
            textBox.Height = 20 * lineHeight;
            if (lineHeight > 1)
            {
                textBlock.VerticalAlignment = VerticalAlignment.Top;
                textBox.AcceptsReturn = true;
            }

            Grid.SetColumn(textBox, 1);
            Grid.SetRow(textBox, row);

            helper.GridFields.Children.Add(textBox);

            helper.BindingActions.Add(
                () => helper.DataElement.set(text.name, textBox.Text));
        }
Example #2
0
        public void CreateField(DetailFormHelper helper, FieldData fieldData)
        {
            var dropDownField = fieldData as DropDownFieldData;
            if (dropDownField == null)
            {
                throw new ArgumentNullException(nameof(dropDownField));
            }

            int rowNr;
            helper.AddRow(fieldData, out rowNr);

            var itemsSource = dropDownField.values.Select(x => new DropDownItem(x)).ToList();
            var dropDown = new ComboBox
            {
                ItemsSource = itemsSource,
                Margin = new Thickness(5),
                Width = 200
            };

            // Tries to find the selected element
            var value = DetailFormHelper.GetValue(helper.DataElement, fieldData.name, fieldData.defaultValue);
            var found = itemsSource.FirstOrDefault(x => x.value == value);
            dropDown.SelectedItem = found;

            Grid.SetColumn(dropDown, 1);
            Grid.SetRow(dropDown, rowNr);

            helper.GridFields.Children.Add(dropDown);

            helper.BindingActions.Add(
                () =>
                {
                    var selectedValue = dropDown.SelectedValue as DropDownItem;
                    if (selectedValue != null)
                    {
                        helper.DataElement.set(fieldData.name, selectedValue?.value);
                    }
                    else
                    {
                        helper.DataElement.unset(fieldData.name);
                    }
                });
        }
Example #3
0
        public void CreateField(DetailFormHelper helper, FieldData fieldData)
        {
            var dateTimeFieldData = fieldData as DateTimeFieldData;
            if (dateTimeFieldData == null)
            {
                throw new ArgumentNullException(nameof(dateTimeFieldData));
            }

            int row;
            helper.AddRow(dateTimeFieldData, out row);

            // Gets the value
            var defaultTime = DateTime.Now;
            var valueObj =
                helper.DataElement.isSet(dateTimeFieldData.name) ?
                    helper.DataElement.get(dateTimeFieldData.name) :
                    (dateTimeFieldData.defaultValue as DateTime?) ?? DateTime.Now;

            DateTimeOffset valueDateTime;
            if (!(valueObj is DateTime))
            {
                if (!DateTimeOffset.TryParse(valueObj.ToString(), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out valueDateTime))
                {
                    valueDateTime = defaultTime;
                }
            }
            else
            {
                valueDateTime = defaultTime;
            }

            var asLocal = valueDateTime.ToLocalTime();

            var stackPanel = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };

            var dateTime = new DatePicker
            {
                Margin = new Thickness(5)
            };

            var time = new TimePicker
            {
                Margin = new Thickness(5)
            };

            Grid.SetColumn(stackPanel, 1);
            Grid.SetRow(stackPanel, row);

            // Adds the fields, dependent on the configuration
            if (dateTimeFieldData.showDate)
            {
                dateTime.Date = asLocal;
                dateTime.CalendarIdentifier = CalendarIdentifiers.Gregorian;
                stackPanel.Children.Add(dateTime);
            }

            if (dateTimeFieldData.showTime)
            {
                time.Time = asLocal.TimeOfDay;
                time.ClockIdentifier = ClockIdentifiers.TwentyFourHour;
                stackPanel.Children.Add(time);
            }

            if (dateTimeFieldData.showOffsetButtons)
            {
                AddOffsetButton(stackPanel, dateTime, "+1 month", TimeSpan.FromDays(30));
                AddOffsetButton(stackPanel, dateTime, "+1 week", TimeSpan.FromDays(7));
                AddOffsetButton(stackPanel, dateTime, "+1 day", TimeSpan.FromDays(1));
            }

            helper.GridFields.Children.Add(stackPanel);

            // Sets the values
            helper.BindingActions.Add(
                () =>
                {
                    var value = new DateTime(2000,1,1);

                    if (dateTimeFieldData.showDate)
                    {
                        value = dateTime.Date.Date;
                    }

                    if (dateTimeFieldData.showTime)
                    {
                        value = value.Add(time.Time);
                    }

                    helper.DataElement.set(dateTimeFieldData.name, value);
                });
        }