Skip to content

Commit 1215857

Browse files
feat(common): add hybrid sample apps (#93)
1 parent fc0b178 commit 1215857

34 files changed

+1023
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31320.298
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebviewAppShared", "WebviewAppShared\WebviewAppShared.csproj", "{0E95EEB3-1734-42A3-A8B7-990BF6184233}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWpfApp", "BlazorWpfApp\BlazorWpfApp.csproj", "{F84C858B-FA3C-433B-AE42-153BD944A9AC}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWinFormsApp", "BlazorWinFormsApp\BlazorWinFormsApp.csproj", "{16DEAB09-359E-4D58-9D8D-22F59E51F989}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{0E95EEB3-1734-42A3-A8B7-990BF6184233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{0E95EEB3-1734-42A3-A8B7-990BF6184233}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{0E95EEB3-1734-42A3-A8B7-990BF6184233}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{0E95EEB3-1734-42A3-A8B7-990BF6184233}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{F84C858B-FA3C-433B-AE42-153BD944A9AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{F84C858B-FA3C-433B-AE42-153BD944A9AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{F84C858B-FA3C-433B-AE42-153BD944A9AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{F84C858B-FA3C-433B-AE42-153BD944A9AC}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{16DEAB09-359E-4D58-9D8D-22F59E51F989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{16DEAB09-359E-4D58-9D8D-22F59E51F989}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{16DEAB09-359E-4D58-9D8D-22F59E51F989}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{16DEAB09-359E-4D58-9D8D-22F59E51F989}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {FE65FC7B-0A9C-4934-9C8E-A55A1209D189}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace BlazorWinFormsApp
5+
{
6+
public class AppState
7+
{
8+
public int Counter { get; set; }
9+
}
10+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0-windows</TargetFramework>
5+
<OutputType>WinExe</OutputType>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
<IsShippingPackage>false</IsShippingPackage>
8+
</PropertyGroup>
9+
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" Version="6.0.0-preview.4.21253.5" />
13+
14+
<!-- the trial version throws an error - disposed renderer - this could be investigated after the official framework is released in case MS fix it-->
15+
<!--<PackageReference Include="Telerik.UI.for.Blazor.Trial" Version="2.24.0" />-->
16+
17+
<!-- the commercial version works as expected -->
18+
<PackageReference Include="Telerik.UI.for.Blazor" Version="2.24.0" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\WebviewAppShared\WebviewAppShared.csproj" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<Content Update="wwwroot\**">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</Content>
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<Content Update="Pages\Counter.razor">
33+
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
34+
</Content>
35+
</ItemGroup>
36+
37+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Windows.Forms;
6+
using Microsoft.AspNetCore.Components.WebView.WindowsForms;
7+
using Microsoft.Extensions.DependencyInjection;
8+
9+
namespace BlazorWinFormsApp
10+
{
11+
public partial class Form1 : Form
12+
{
13+
private readonly AppState _appState = new();
14+
15+
public Form1()
16+
{
17+
var serviceCollection = new ServiceCollection();
18+
serviceCollection.AddBlazorWebView();
19+
serviceCollection.AddSingleton<AppState>(_appState);
20+
InitializeComponent();
21+
22+
blazorWebView1.HostPage = @"wwwroot\index.html";
23+
blazorWebView1.Services = serviceCollection.BuildServiceProvider();
24+
blazorWebView1.RootComponents.Add<Main>("#app");
25+
}
26+
}
27+
}

common/hybrid-blazor-apps/BlazorWinFormsApp/Form1.designer.cs

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<TelerikRootComponent>
2+
<div id="viewportSpacer">
3+
<Router AppAssembly="@GetType().Assembly">
4+
<Found Context="routeData">
5+
<NavLink href="" Match="NavLinkMatch.All">Home</NavLink> |
6+
<NavLink href="other">Other</NavLink>
7+
<hr />
8+
<RouteView RouteData="@routeData" />
9+
</Found>
10+
<NotFound>
11+
<h1>Not found</h1>
12+
<p>Sorry, there's nothing here.</p>
13+
</NotFound>
14+
</Router>
15+
</div>
16+
</TelerikRootComponent>
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
@page "/"
2+
3+
@* NOTE: The full namespace for other proejcts and native code is included here to work around this bug: https://github.com/dotnet/aspnetcore/issues/30851 *@
4+
@inject BlazorWinFormsApp.AppState AppState
5+
6+
<h3> <a href="https://www.telerik.com/blazor-ui" target="_blank">Telerik UI for Blazor</a> running in a native WinForms app!</h3>
7+
8+
9+
<h3>Grid</h3>
10+
11+
<TelerikGrid Data="@GridData"
12+
Pageable="true"
13+
PageSize="10"
14+
Reorderable="true"
15+
Groupable="true"
16+
Height="400px"
17+
Sortable="true"
18+
Resizable="true"
19+
FilterMode="@GridFilterMode.FilterRow">
20+
<GridColumns>
21+
<GridColumn Field="@nameof(Product.ProductId)" />
22+
<GridColumn Field="@nameof(Product.ProductName)" />
23+
<GridColumn Field="@nameof(Product.UnitsInStock)" />
24+
<GridColumn Field="@nameof(Product.UnitPrice)" />
25+
<GridColumn Field="@nameof(Product.CreatedAt)" />
26+
<GridColumn Field="@nameof(Product.Discontinued)" />
27+
</GridColumns>
28+
</TelerikGrid>
29+
30+
<h3>Button</h3>
31+
32+
<TelerikButton OnClick="@OnClick" Primary="true" Icon="plus">Click me</TelerikButton>
33+
34+
<div>
35+
The button was clicked @(AppState.Counter) times.
36+
</div>
37+
38+
<h3>DatePicker</h3>
39+
@SelectedDate
40+
<br />
41+
<TelerikDatePicker Min="@Min" Max="@Max" @bind-Value="@SelectedDate"></TelerikDatePicker>
42+
43+
<h3>Chart</h3>
44+
45+
<TelerikChart Width="600px" Height="300px">
46+
<ChartSeriesItems>
47+
<ChartSeries Type="ChartSeriesType.Column"
48+
Name="Product 1"
49+
Data="@ChartSeries1Data"
50+
Field="@nameof(ChartSeriesData.Product1Sales)"
51+
CategoryField="@nameof(ChartSeriesData.Year)">
52+
</ChartSeries>
53+
54+
<ChartSeries Type="ChartSeriesType.Column"
55+
Name="Product 2"
56+
Data="@ChartSeries2Data"
57+
Field="@nameof(ChartSeriesData.Product1Sales)"
58+
CategoryField="@nameof(ChartSeriesData.Year)">
59+
</ChartSeries>
60+
</ChartSeriesItems>
61+
<ChartTooltip Visible="true" Shared="true">
62+
</ChartTooltip>
63+
<ChartCategoryAxes>
64+
<ChartCategoryAxis>
65+
<ChartCategoryAxisLabels Format="{0:dd MMM yyyy}" />
66+
</ChartCategoryAxis>
67+
</ChartCategoryAxes>
68+
</TelerikChart>
69+
70+
71+
@code {
72+
public DateTime Min = new DateTime(2000, 1, 1);
73+
public DateTime Max = new DateTime(2050, 12, 31);
74+
public DateTime? SelectedDate;
75+
76+
public List<Product> GridData { get; set; }
77+
78+
List<ChartSeriesData> ChartSeries1Data { get; set; } = new List<ChartSeriesData>();
79+
List<ChartSeriesData> ChartSeries2Data { get; set; } = new List<ChartSeriesData>();
80+
81+
protected override void OnInitialized()
82+
{
83+
GridData = GetProductData();
84+
ChartSeries1Data = GetSeriesData();
85+
ChartSeries2Data = GetSeriesData();
86+
}
87+
88+
private List<Product> GetProductData(int count = 100)
89+
{
90+
var products = new List<Product>();
91+
92+
for (var i = 1; i <= count; i++)
93+
{
94+
var product = new Product()
95+
{
96+
ProductId = i,
97+
ProductName = "Product" + i.ToString(),
98+
UnitPrice = (decimal)(i * 3.14),
99+
UnitsInStock = (short)((i * 1) % 9),
100+
Discontinued = i % 3 == 0,
101+
CreatedAt = new DateTime(2019, 1 + (i % 12), 1 + (i % 29))
102+
};
103+
104+
products.Add(product);
105+
}
106+
107+
return products;
108+
}
109+
110+
public static List<ChartSeriesData> GetSeriesData()
111+
{
112+
List<ChartSeriesData> data = new List<ChartSeriesData>();
113+
114+
for (int i = 1; i <= 3; i++)
115+
{
116+
var dataItem = new ChartSeriesData
117+
{
118+
Product1Sales = i,
119+
Product2Sales = i + 1.123,
120+
Year = new DateTime(2000 + i, 3, i),
121+
SegmentName = $"{i * 100}"
122+
};
123+
124+
data.Add(dataItem);
125+
}
126+
127+
return data;
128+
}
129+
130+
public void OnClick()
131+
{
132+
AppState.Counter++;
133+
}
134+
135+
public class Product
136+
{
137+
public Product()
138+
{
139+
}
140+
141+
public int ProductId { get; set; }
142+
public string ProductName { get; set; }
143+
public decimal? UnitPrice { get; set; }
144+
public short? UnitsInStock { get; set; }
145+
public bool Discontinued { get; set; }
146+
public DateTime? CreatedAt { get; set; }
147+
}
148+
149+
public class ChartSeriesData
150+
{
151+
public int Product1Sales { get; set; }
152+
public double Product2Sales { get; set; }
153+
public DateTime Year { get; set; }
154+
public string SegmentName { get; set; }
155+
}
156+
}

0 commit comments

Comments
 (0)