public static void Main() { // equivalent to <h1>Hello World</h1>: var header = new Element("h1") { TextContent = "Hello World" }; // equivalent to document.getElementById("target"): var target = Element.GetById("target"); target.AppendChild(header); // Hook up mouse events to the element, changing the background color on hover: header.MouseOver += (s, e) => { header.SetStyle("background-color", "#f00"); }; header.MouseOut += (s, e) => { header.SetStyle("background-color", "#fff"); }; }
public static void Main() { var w = 800; var h = 600; // create a new Canvas var canvas = new Canvas(); canvas.Width = w; canvas.Height = h; // add canvas to the div with id = "target" (defined in MainPage.html) var target = Element.GetById("target"); target.AppendChild(canvas); // get the 2D context for the canvas, which contains all the draw methods var context = canvas.Get2DContext(); var angleOffset = 0d; var timer = new IntervalDispatcher(TimeSpan.FromMilliseconds(30)); timer.Tick += (s, e) => { // draw background rect context.FillStyle = new RgbStyle(0xcc, 0x66, 0x99); context.FillRect(0, 0, w, h); context.LineWidth = 2; // draw flowers context.StrokeStyle = new RgbStyle(0x33, 0x33, 0x33); context.FillStyle = new RgbStyle(0xff, 0xff, 0); DrawFlower(context, Math.Min(w, h) * 0.4, 25d, 0.5 * w, 0.5 * h, angleOffset); context.FillStyle = new RgbStyle(0xff, 0x0, 0); DrawFlower(context, Math.Min(w, h) * 0.1, 12d, 0.5 * w, 0.5 * h, angleOffset); angleOffset += 0.02; }; timer.Start(); bool started = true; var startButton = new Element("button") { TextContent = "Start" }; var stopButton = new Element("button") { TextContent = "Stop" }; startButton.Click += (s, e) => { timer.Start(); started = true; startButton.Enabled = !started; stopButton.Enabled = started; }; stopButton.Click += (s, e) => { timer.Stop(); started = false; startButton.Enabled = !started; stopButton.Enabled = started; }; startButton.Enabled = !started; stopButton.Enabled = started; target.AppendChild(startButton); target.AppendChild(stopButton); }
public ElementWrapper(Element childElement) : base("div") { Content = childElement; }
protected override Element Prepare(Element childElement) { var wrapper = base.Prepare(childElement); wrapper.SetStyle("clear", "both"); return wrapper; }
public virtual void AppendChild(Element childElement) { }
public virtual void RemoveChild(Element child) { }
public Style(Element element) { _element = element; }