private static ComboBox CreateComboBox(DataEntryControls styleProvider, ControlRow control)
        {
            ComboBox comboBox = new ComboBox()
            {
                ToolTip = control.Tooltip,
                Width   = control.Width,
                Style   = styleProvider.FindResource(ControlContentStyleEnum.ChoiceComboBox.ToString()) as Style
            };

            // Add items to the combo box
            List <string> choices = control.GetChoices(out bool includesEmptyChoice);

            foreach (string choice in choices)
            {
                comboBox.Items.Add(choice);
            }
            if (includesEmptyChoice)
            {
                // put empty choices at the end below a separator for visual clarity
                comboBox.Items.Add(new Separator());
                comboBox.Items.Add(String.Empty);
            }
            comboBox.SelectedIndex = 0;
            return(comboBox);
        }
 public QuickPasteEditor(QuickPasteEntry quickPasteEntry, FileDatabase fileDatabase, DataEntryControls dataEntryControls)
 {
     this.InitializeComponent();
     this.QuickPasteEntry   = quickPasteEntry;
     this.fileDatabase      = fileDatabase;
     this.dataEntryControls = dataEntryControls;
 }
        private static Label CreateLabel(DataEntryControls styleProvider, ControlRow control)
        {
            Label label = new Label()
            {
                Content = control.Label,
                ToolTip = control.Tooltip,
                Style   = styleProvider.FindResource(ControlLabelStyleEnum.DefaultLabel.ToString()) as Style
            };

            return(label);
        }
        private static RadioButton CreateCounterLabelButton(DataEntryControls styleProvider, ControlRow control)
        {
            RadioButton radioButton = new RadioButton()
            {
                GroupName = "DataEntryCounter",
                Content   = control.Label,
                ToolTip   = control.Tooltip,
                Style     = styleProvider.FindResource(ControlLabelStyleEnum.CounterButton.ToString()) as Style
            };

            return(radioButton);
        }
        private static TextBox CreateTextBox(DataEntryControls styleProvider, ControlRow control)
        {
            TextBox textBox = new TextBox()
            {
                Text    = control.DefaultValue,
                ToolTip = control.Tooltip,
                Width   = control.Width,
                Style   = styleProvider.FindResource(ControlContentStyleEnum.NoteTextBox.ToString()) as Style
            };

            return(textBox);
        }
        // Returns a stack panel containing two controls
        // The stack panel ensures that controls are layed out as a single unit with certain spatial characteristcs
        // i.e.,  a given height, right margin, where contents will not be broken durring (say) panel wrapping
        private static StackPanel CreateStackPanel(DataEntryControls styleProvider, Control label, Control content)
        {
            StackPanel stackPanel = new StackPanel();

            stackPanel.Children.Add(label);
            stackPanel.Children.Add(content);

            Style style = styleProvider.FindResource(Constant.ControlStyle.ContainerStyle) as Style;

            stackPanel.Style = style;
            return(stackPanel);
        }
        private CheckBox CreateFlag(DataEntryControls styleProvider, ControlRow control)
        {
            CheckBox checkBox = new CheckBox()
            {
                Visibility = Visibility.Visible,
                ToolTip    = control.Tooltip,
                Style      = styleProvider.FindResource(ControlContentStyleEnum.FlagCheckBox.ToString()) as Style
            };

            checkBox.GotFocus  += this.Control_GotFocus;
            checkBox.LostFocus += this.Control_LostFocus;
            return(checkBox);
        }
        private static IntegerUpDown CreateIntegerUpDown(DataEntryControls styleProvider, ControlRow control)
        {
            IntegerUpDown integerUpDown = new IntegerUpDown()
            {
                Text    = control.DefaultValue,
                ToolTip = control.Tooltip,
                Minimum = 0,
                Width   = control.Width + 18, // accounts for the width of the spinner
                DisplayDefaultValueOnEmptyText = true,
                DefaultValue          = null,
                UpdateValueOnEnterKey = true,
                Style = styleProvider.FindResource(ControlContentStyleEnum.CounterTextBox.ToString()) as Style
            };

            return(integerUpDown);
        }
        public void Generate(WrapPanel parent, DataTableBackedList <ControlRow> templateTable)
        {
            // used for styling all content and label controls except ComboBoxes since the combo box style is commented out in DataEntryControls.xaml
            // and defined instead in MainWindow.xaml as an exception workaround
            DataEntryControls styleProvider = new DataEntryControls();

            parent.Children.Clear();
            foreach (ControlRow control in templateTable)
            {
                // instantiate control UX objects
                StackPanel stackPanel;
                switch (control.Type)
                {
                case Constant.Control.Note:
                case Constant.DatabaseColumn.Date:
                case Constant.DatabaseColumn.File:
                case Constant.DatabaseColumn.Folder:
                case Constant.DatabaseColumn.RelativePath:
                case Constant.DatabaseColumn.Time:
                    Label   noteLabel   = EditorControls.CreateLabel(styleProvider, control);
                    TextBox noteContent = EditorControls.CreateTextBox(styleProvider, control);
                    stackPanel = EditorControls.CreateStackPanel(styleProvider, noteLabel, noteContent);
                    break;

                case Constant.Control.Counter:
                    RadioButton   counterLabel   = EditorControls.CreateCounterLabelButton(styleProvider, control);
                    IntegerUpDown counterContent = EditorControls.CreateIntegerUpDown(styleProvider, control);
                    stackPanel                = EditorControls.CreateStackPanel(styleProvider, counterLabel, counterContent);
                    counterLabel.IsTabStop    = false;
                    counterContent.GotFocus  += this.Control_GotFocus;
                    counterContent.LostFocus += this.Control_LostFocus;
                    break;

                case Constant.Control.Flag:
                case Constant.DatabaseColumn.DeleteFlag:
                    Label    flagLabel   = EditorControls.CreateLabel(styleProvider, control);
                    CheckBox flagContent = this.CreateFlag(styleProvider, control);
                    flagContent.IsChecked = String.Equals(control.DefaultValue, Constant.BooleanValue.True, StringComparison.OrdinalIgnoreCase) ? true : false;
                    stackPanel            = EditorControls.CreateStackPanel(styleProvider, flagLabel, flagContent);
                    break;

                case Constant.Control.FixedChoice:
                case Constant.DatabaseColumn.ImageQuality:
                    Label    choiceLabel   = EditorControls.CreateLabel(styleProvider, control);
                    ComboBox choiceContent = EditorControls.CreateComboBox(styleProvider, control);
                    stackPanel = EditorControls.CreateStackPanel(styleProvider, choiceLabel, choiceContent);
                    break;

                case Constant.DatabaseColumn.DateTime:
                    Label          dateTimeLabel   = EditorControls.CreateLabel(styleProvider, control);
                    DateTimePicker dateTimeContent = this.CreateDateTimePicker(control);
                    stackPanel = EditorControls.CreateStackPanel(styleProvider, dateTimeLabel, dateTimeContent);
                    break;

                case Constant.DatabaseColumn.UtcOffset:
                    Label           utcOffsetLabel   = EditorControls.CreateLabel(styleProvider, control);
                    UtcOffsetUpDown utcOffsetContent = this.CreateUtcOffsetPicker(control);
                    stackPanel = EditorControls.CreateStackPanel(styleProvider, utcOffsetLabel, utcOffsetContent);
                    break;

                default:
                    throw new NotSupportedException(String.Format("Unhandled control type {0}.", control.Type));
                }

                stackPanel.Tag = control.DataLabel;
                if (control.Visible == false)
                {
                    stackPanel.Visibility = Visibility.Collapsed;
                }

                // add control to wrap panel
                parent.Children.Add(stackPanel);
            }
        }