Added web assembly

This commit is contained in:
2022-01-22 21:54:41 +01:00
parent 7408890bca
commit 12e542800a
37 changed files with 1374 additions and 0 deletions

View File

@ -0,0 +1,45 @@
@page "/counter"
@using System.Diagnostics
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @_currentCount</p>
<p role="status">Runtime: @_stopwatch.Elapsed.ToString("g")</p>
<button class="btn btn-success" @onclick="Start">Start</button>
<button class="btn btn-danger" @onclick="Stop">Stop</button>
<button class="btn btn-secondary" @onclick="Reset">Reset</button>
@code {
private int _currentCount = 0;
private bool _cancel;
private readonly Stopwatch _stopwatch = new();
private async Task Start()
{
_stopwatch.Start();
_cancel = false;
while (!_cancel)
{
_currentCount++;
StateHasChanged();
await Task.Delay(10);
}
_stopwatch.Stop();
}
private void Stop()
{
_cancel = true;
}
private void Reset()
{
_cancel = true;
_currentCount = 0;
_stopwatch.Reset();
}
}

View File

@ -0,0 +1,57 @@
@page "/fetchdata"
@inject HttpClient Http
<PageTitle>Weather forecast</PageTitle>
<h1>Weather forecast</h1>
<p>This component demonstrates fetching data from the server.</p>
@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View File

@ -0,0 +1,9 @@
@page "/"
<PageTitle>Index</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />