Last active
April 11, 2018 19:52
-
-
Save gskachkov/3985d3f96dfbaa411704149b2e85fe21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Route("/counter"), Layout(typeof(MainLayout))] | |
public class Counter : BlazorComponent | |
{ | |
private int currCount = 0; | |
protected override void BuildRenderTree(RenderTreeBuilder builder) | |
{ | |
base.BuildRenderTree(builder); | |
builder.OpenElement(0, "h1"); | |
builder.AddContent(1, "Counter"); | |
builder.CloseElement(); | |
builder.AddContent(2, "\n\n"); | |
builder.OpenElement(3, "p"); | |
builder.AddContent(4, " Start count: "); | |
builder.OpenElement(5, "input"); | |
builder.AddAttribute(6, "type", "text"); | |
builder.AddAttribute( | |
7, | |
"value", | |
(int) BindMethods. | |
GetValue<int>(this.currCount)); | |
builder.AddAttribute(8, | |
base.onchange( | |
BindMethods.SetValue( | |
new Action<int>(this, this.<BuildRenderTree>b__0_0), | |
this.currCount | |
) | |
) | |
); | |
builder.CloseElement(); | |
builder.AddContent(9, " "); | |
builder.CloseElement(); | |
builder.AddContent(10, "\n"); | |
builder.OpenElement(11, "p"); | |
builder.AddContent(12, "Current count: "); | |
builder.AddContent(13, (int) this.currCount); | |
builder.CloseElement(); | |
builder.AddContent(14, "\n\n"); | |
builder.OpenElement(15, "button"); | |
builder.AddAttribute( | |
0x10, | |
base.onclick(new Action(this, this.IncCount)) | |
); | |
builder.AddContent(0x11, "Click me"); | |
builder.CloseElement(); | |
builder.AddContent(0x12, "\n\n"); | |
} | |
private void IncCount() | |
{ | |
this.currCount++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment