Ooui-tws-port/Samples/TodoSample.cs

54 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using Ooui;
namespace Samples
{
public class TodoSample
{
List items = new List ();
Element MakeItem (string text)
{
var li = new ListItem ();
var check = new Input {
Type = InputType.Checkbox,
};
var label = new Label {
Text = text,
For = check
};
li.AppendChild (check);
li.AppendChild (label);
return li;
}
Element MakeTodo ()
{
var input = new Input ();
var button = new Button ("Add the item");
button.Clicked += (s, e) => {
if (string.IsNullOrWhiteSpace (input.Value))
return;
var item = MakeItem (input.Value);
items.AppendChild (item);
input.Value = "";
};
var app = new Div ();
app.AppendChild (input);
app.AppendChild (button);
app.AppendChild (items);
return app;
}
public void Publish ()
{
var b = MakeTodo ();
UI.Publish ("/todo", MakeTodo);
}
}
}