Skip to content

Commit 027b286

Browse files
feat: Blazor Desktop (#1)
* feat: Blazor Desktop * Add nuget package info * remove test code from sample project * Remove extra csproj * added templates * Updated template to use WinExe
1 parent c087dec commit 027b286

82 files changed

Lines changed: 3695 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/nuget.png

1.12 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
root = true

src/BlazorDesktop.Sample/App.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0-windows</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<UseWPF>true</UseWPF>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\BlazorDesktop\BlazorDesktop.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace BlazorDesktop.Data
2+
{
3+
public class WeatherForecast
4+
{
5+
public DateTime Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace BlazorDesktop.Data
2+
{
3+
public class WeatherForecastService
4+
{
5+
private static readonly string[] Summaries = new[]
6+
{
7+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
8+
};
9+
10+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
11+
{
12+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
13+
{
14+
Date = startDate.AddDays(index),
15+
TemperatureC = Random.Shared.Next(-20, 55),
16+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
17+
}).ToArray());
18+
}
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/counter"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter</h1>
6+
7+
<p role="status">Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+
@code {
12+
private int currentCount = 0;
13+
14+
private void IncrementCount()
15+
{
16+
currentCount++;
17+
}
18+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@page "/fetchdata"
2+
3+
@using BlazorDesktop.Data
4+
5+
@inject WeatherForecastService ForecastService
6+
7+
<PageTitle>Weather forecast</PageTitle>
8+
9+
<h1>Weather forecast</h1>
10+
11+
<p>This component demonstrates fetching data from the server.</p>
12+
13+
@if (forecasts == null)
14+
{
15+
<p><em>Loading...</em></p>
16+
}
17+
else
18+
{
19+
<table class="table">
20+
<thead>
21+
<tr>
22+
<th>Date</th>
23+
<th>Temp. (C)</th>
24+
<th>Temp. (F)</th>
25+
<th>Summary</th>
26+
</tr>
27+
</thead>
28+
<tbody>
29+
@foreach (var forecast in forecasts)
30+
{
31+
<tr>
32+
<td>@forecast.Date.ToShortDateString()</td>
33+
<td>@forecast.TemperatureC</td>
34+
<td>@forecast.TemperatureF</td>
35+
<td>@forecast.Summary</td>
36+
</tr>
37+
}
38+
</tbody>
39+
</table>
40+
}
41+
42+
@code {
43+
private WeatherForecast[]? forecasts;
44+
45+
protected override async Task OnInitializedAsync()
46+
{
47+
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
48+
}
49+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@page "/"
2+
3+
<PageTitle>Index</PageTitle>
4+
5+
<h1>Hello, world!</h1>
6+
7+
Welcome to your new app.
8+
9+
<SurveyPrompt Title="How is Blazor working for you?" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using BlazorDesktop.Data;
2+
using BlazorDesktop.Hosting;
3+
using BlazorDesktop.Sample;
4+
using Microsoft.AspNetCore.Components.Web;
5+
6+
var builder = BlazorDesktopHostBuilder.CreateDefault(args);
7+
builder.RootComponents.Add<App>("#app");
8+
builder.RootComponents.Add<HeadOutlet>("head::after");
9+
10+
builder.Services.AddSingleton<WeatherForecastService>();
11+
12+
await builder.Build().RunAsync();

0 commit comments

Comments
 (0)