aspnetcore/test/testapps/BasicTestApp/CounterComponent.cs

36 lines
1022 B
C#

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Blazor.Components;
using Microsoft.Blazor.UITree;
namespace BasicTestApp
{
public class CounterComponent : IComponent
{
private int currentCount = 0;
public void BuildUITree(UITreeBuilder builder)
{
builder.OpenElement("h1");
builder.AddText("Counter");
builder.CloseElement();
builder.OpenElement("p");
builder.AddText("Current count: ");
builder.AddText(currentCount.ToString());
builder.CloseElement();
builder.OpenElement("button");
builder.AddAttribute("onclick", OnButtonClicked);
builder.AddText("Click me");
builder.CloseElement();
}
private void OnButtonClicked(UIEventInfo eventInfo)
{
currentCount++;
}
}
}