Ejemplo n.º 1
0
 public MultiselectSample()
 {
     _select = new Select
     {
         Id       = "mymulti",
         Class    = "form-control",
         Multiple = true
     };
     _toggle = new Button
     {
         Class = "btn btn-primary ml-2"
     };
     _toggle.AppendChild(new TextNode("Toggle"));
     _select.AddOption("N", "North");
     _select.AddOption("E", "East");
     _select.AddOption("S", "South");
     _select.AddOption("W", "West");
     _toggle.On("click", app =>
     {
         foreach (var child in _select.Children)
         {
             if (child is Option option)
             {
                 option.Selected = !option.Selected;
             }
         }
         return(Task.CompletedTask);
     });
 }
Ejemplo n.º 2
0
 public SelectSample()
 {
     _select = new Select
     {
         Id    = "myselect",
         Class = "form-control",
     };
     _advance = new Button
     {
         Class = "btn btn-primary ml-2"
     };
     _advance.AppendChild(new TextNode("Advance"));
     _select.AddOption("0", "Monday");
     _select.AddOption("1", "Tuesday");
     _select.AddOption("2", "Wednesday");
     _select.AddOption("3", "Thursday");
     _select.AddOption("4", "Friday");
     _select.AddOption("5", "Saturday");
     _select.AddOption("6", "Sunday");
     _advance.On("click", app =>
     {
         int.TryParse(_select.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out int weekday);
         weekday       = (weekday + 1) % 7;
         _select.Value = weekday.ToString(CultureInfo.InvariantCulture);
         return(Task.CompletedTask);
     });
 }
Ejemplo n.º 3
0
        public Element CreateElement()
        {
            var heading  = new Heading("Draw");
            var subtitle = new Paragraph("Click to draw a masterpiece");
            var toolSel  = new Select();

            toolSel.AppendChild(new Option {
                Text = "Boxes", Value = "box"
            });
            toolSel.AddOption("Circles", "circle");
            var canvas = new Canvas
            {
                Width  = 320,
                Height = 240,
            };
            var context = canvas.GetContext2D();

            canvas.Click += (s, e) =>
            {
                var radius = 10;
                context.BeginPath();
                if (toolSel.Value == "box")
                {
                    context.Rect(e.OffsetX - radius, e.OffsetY - radius, 2 * radius, 2 * radius);
                }
                else
                {
                    context.Arc(e.OffsetX, e.OffsetY, radius, 0, 2 * Math.PI, true);
                }

                context.Fill();
            };
            canvas.Style.Cursor      = "pointer";
            canvas.Style.BorderColor = "#CCC";
            canvas.Style.BorderStyle = "solid";
            canvas.Style.BorderWidth = "1px";

            var clearbtn = new Button("Clear")
            {
                Type      = ButtonType.Submit,
                ClassName = "btn btn-danger",
            };

            clearbtn.Click += (s, e) => {
                context.ClearRect(0, 0, canvas.Width, canvas.Height);
            };
            clearbtn.Style.Display = "block";

            var app = new Div();

            app.AppendChild(heading);
            app.AppendChild(subtitle);
            app.AppendChild(new Div(toolSel));
            app.AppendChild(canvas);
            app.AppendChild(clearbtn);
            return(app);
        }
Ejemplo n.º 4
0
 public static Select <THelper> AddOptions <THelper>(this Select <THelper> select, params object[] options)
     where THelper : BootstrapHelper <THelper>
 {
     select.Options.Clear();
     foreach (object option in options)
     {
         select.AddOption(option);
     }
     return(select);
 }