示例#1
0
        private void ElementTypeComboBoxOnOnFormEvent(object sender, FormElementEvent e)
        {
            var oldElement = FormElement;

            if (!(e is SelectElementChangedEvent eventArgs))
            {
                return;
            }

            if (ElementTypeToFriendlyName(FormElement?.Model.GetType()) == eventArgs.NewValue)
            {
                return;
            }

            IControlElementViewModel newElementViewModel = null;

            switch (eventArgs.NewValue)
            {
            case "Button":
                newElementViewModel =
                    new ButtonElementViewModel(new ButtonElementBuilder().FromTemplate(oldElement.Model)
                                               .Build());
                break;

            case "Html":
                newElementViewModel =
                    new HtmlElementViewModel(new HtmlElementBuilder().FromTemplate(oldElement.Model)
                                             .Build());
                break;

            case "CheckBox":
                newElementViewModel =
                    new CheckElementViewModel(new CheckElementBuilder().FromTemplate(oldElement.Model)
                                              .Build());
                break;

            case "TextBox":
                newElementViewModel =
                    new TextElementViewModel(new TextElementBuilder().FromTemplate(oldElement.Model)
                                             .Build());
                break;

            case "ComboBox":
                newElementViewModel =
                    new SelectElementViewModel(new SelectElementBuilder().FromTemplate(oldElement.Model)
                                               .Build());
                break;
            }

            var elementIndex = ParentElement.Children.IndexOf(oldElement);

            ParentElement.Children.RemoveAt(elementIndex);
            ParentElement.Children.Insert(elementIndex, newElementViewModel);
            FormElement = newElementViewModel;
        }
        private void AddHtmlConfigurationRows(FormGroup group, HtmlElementViewModel element)
        {
            var textField = new TextField("htmlContent", LabelPosition.AboveElement, "Html",
                                          new ValidationRule <TextField>[]
            {
            }, element.Content);

            textField.OnFormEvent += (s, e) =>
            {
                if (e is TextFieldChangedEventArgs eventArgs)
                {
                    element.Content = eventArgs.NewContent;
                }
            };

            group.Rows.Add(new FormRow(1, new[]
            {
                new FormColumn(1, textField)
            }));
        }
示例#3
0
        private void AddHtmlConfigurationRows(ICompositeElementViewModel group, HtmlElementViewModel element)
        {
            var buttonField =
                new ButtonElementViewModel(
                    new ButtonElementBuilder()
                    .SetName("editHtml")
                    .SetLabel(ElementLabel.Left("Edit"))
                    .SetContent("Edit").Build());

            buttonField.OnFormEvent += (s, e) =>
            {
                if (e is ButtonElementClickedEvent eventArgs)
                {
                    var htmlEditor = new HtmlEditorDialog(element.Content);
                    htmlEditor.ShowDialog();

                    element.Content = htmlEditor.ViewModel.Content;
                    Refresh();
                }
            };

            group.Children.Add(buttonField);
        }