Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions common/hybrid-blazor-apps/BlazorHybridApps.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31320.298
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebviewAppShared", "WebviewAppShared\WebviewAppShared.csproj", "{0E95EEB3-1734-42A3-A8B7-990BF6184233}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWpfApp", "BlazorWpfApp\BlazorWpfApp.csproj", "{F84C858B-FA3C-433B-AE42-153BD944A9AC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWinFormsApp", "BlazorWinFormsApp\BlazorWinFormsApp.csproj", "{16DEAB09-359E-4D58-9D8D-22F59E51F989}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0E95EEB3-1734-42A3-A8B7-990BF6184233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E95EEB3-1734-42A3-A8B7-990BF6184233}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E95EEB3-1734-42A3-A8B7-990BF6184233}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E95EEB3-1734-42A3-A8B7-990BF6184233}.Release|Any CPU.Build.0 = Release|Any CPU
{F84C858B-FA3C-433B-AE42-153BD944A9AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F84C858B-FA3C-433B-AE42-153BD944A9AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F84C858B-FA3C-433B-AE42-153BD944A9AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F84C858B-FA3C-433B-AE42-153BD944A9AC}.Release|Any CPU.Build.0 = Release|Any CPU
{16DEAB09-359E-4D58-9D8D-22F59E51F989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16DEAB09-359E-4D58-9D8D-22F59E51F989}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16DEAB09-359E-4D58-9D8D-22F59E51F989}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16DEAB09-359E-4D58-9D8D-22F59E51F989}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FE65FC7B-0A9C-4934-9C8E-A55A1209D189}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions common/hybrid-blazor-apps/BlazorWinFormsApp/AppState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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.

namespace BlazorWinFormsApp
{
public class AppState
{
public int Counter { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<UseWindowsForms>true</UseWindowsForms>
<IsShippingPackage>false</IsShippingPackage>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" Version="6.0.0-preview.4.21253.5" />

<!-- the trial version throws an error - disposed renderer - this could be investigated after the official framework is released in case MS fix it-->
<!--<PackageReference Include="Telerik.UI.for.Blazor.Trial" Version="2.24.0" />-->

<!-- the commercial version works as expected -->
<PackageReference Include="Telerik.UI.for.Blazor" Version="2.24.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WebviewAppShared\WebviewAppShared.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<Content Update="Pages\Counter.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions common/hybrid-blazor-apps/BlazorWinFormsApp/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 System;
using System.Windows.Forms;
using Microsoft.AspNetCore.Components.WebView.WindowsForms;
using Microsoft.Extensions.DependencyInjection;

namespace BlazorWinFormsApp
{
public partial class Form1 : Form
{
private readonly AppState _appState = new();

public Form1()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddBlazorWebView();
serviceCollection.AddSingleton<AppState>(_appState);
InitializeComponent();

blazorWebView1.HostPage = @"wwwroot\index.html";
blazorWebView1.Services = serviceCollection.BuildServiceProvider();
blazorWebView1.RootComponents.Add<Main>("#app");
}
}
}
90 changes: 90 additions & 0 deletions common/hybrid-blazor-apps/BlazorWinFormsApp/Form1.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions common/hybrid-blazor-apps/BlazorWinFormsApp/Main.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<TelerikRootComponent>
<div id="viewportSpacer">
<Router AppAssembly="@GetType().Assembly">
<Found Context="routeData">
<NavLink href="" Match="NavLinkMatch.All">Home</NavLink> |
<NavLink href="other">Other</NavLink>
<hr />
<RouteView RouteData="@routeData" />
</Found>
<NotFound>
<h1>Not found</h1>
<p>Sorry, there's nothing here.</p>
</NotFound>
</Router>
</div>
</TelerikRootComponent>
156 changes: 156 additions & 0 deletions common/hybrid-blazor-apps/BlazorWinFormsApp/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
@page "/"

@* 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 *@
@inject BlazorWinFormsApp.AppState AppState

<h3> <a href="https://www.telerik.com/blazor-ui" target="_blank">Telerik UI for Blazor</a> running in a native WinForms app!</h3>


<h3>Grid</h3>

<TelerikGrid Data="@GridData"
Pageable="true"
PageSize="10"
Reorderable="true"
Groupable="true"
Height="400px"
Sortable="true"
Resizable="true"
FilterMode="@GridFilterMode.FilterRow">
<GridColumns>
<GridColumn Field="@nameof(Product.ProductId)" />
<GridColumn Field="@nameof(Product.ProductName)" />
<GridColumn Field="@nameof(Product.UnitsInStock)" />
<GridColumn Field="@nameof(Product.UnitPrice)" />
<GridColumn Field="@nameof(Product.CreatedAt)" />
<GridColumn Field="@nameof(Product.Discontinued)" />
</GridColumns>
</TelerikGrid>

<h3>Button</h3>

<TelerikButton OnClick="@OnClick" Primary="true" Icon="plus">Click me</TelerikButton>

<div>
The button was clicked @(AppState.Counter) times.
</div>

<h3>DatePicker</h3>
@SelectedDate
<br />
<TelerikDatePicker Min="@Min" Max="@Max" @bind-Value="@SelectedDate"></TelerikDatePicker>

<h3>Chart</h3>

<TelerikChart Width="600px" Height="300px">
<ChartSeriesItems>
<ChartSeries Type="ChartSeriesType.Column"
Name="Product 1"
Data="@ChartSeries1Data"
Field="@nameof(ChartSeriesData.Product1Sales)"
CategoryField="@nameof(ChartSeriesData.Year)">
</ChartSeries>

<ChartSeries Type="ChartSeriesType.Column"
Name="Product 2"
Data="@ChartSeries2Data"
Field="@nameof(ChartSeriesData.Product1Sales)"
CategoryField="@nameof(ChartSeriesData.Year)">
</ChartSeries>
</ChartSeriesItems>
<ChartTooltip Visible="true" Shared="true">
</ChartTooltip>
<ChartCategoryAxes>
<ChartCategoryAxis>
<ChartCategoryAxisLabels Format="{0:dd MMM yyyy}" />
</ChartCategoryAxis>
</ChartCategoryAxes>
</TelerikChart>


@code {
public DateTime Min = new DateTime(2000, 1, 1);
public DateTime Max = new DateTime(2050, 12, 31);
public DateTime? SelectedDate;

public List<Product> GridData { get; set; }

List<ChartSeriesData> ChartSeries1Data { get; set; } = new List<ChartSeriesData>();
List<ChartSeriesData> ChartSeries2Data { get; set; } = new List<ChartSeriesData>();

protected override void OnInitialized()
{
GridData = GetProductData();
ChartSeries1Data = GetSeriesData();
ChartSeries2Data = GetSeriesData();
}

private List<Product> GetProductData(int count = 100)
{
var products = new List<Product>();

for (var i = 1; i <= count; i++)
{
var product = new Product()
{
ProductId = i,
ProductName = "Product" + i.ToString(),
UnitPrice = (decimal)(i * 3.14),
UnitsInStock = (short)((i * 1) % 9),
Discontinued = i % 3 == 0,
CreatedAt = new DateTime(2019, 1 + (i % 12), 1 + (i % 29))
};

products.Add(product);
}

return products;
}

public static List<ChartSeriesData> GetSeriesData()
{
List<ChartSeriesData> data = new List<ChartSeriesData>();

for (int i = 1; i <= 3; i++)
{
var dataItem = new ChartSeriesData
{
Product1Sales = i,
Product2Sales = i + 1.123,
Year = new DateTime(2000 + i, 3, i),
SegmentName = $"{i * 100}"
};

data.Add(dataItem);
}

return data;
}

public void OnClick()
{
AppState.Counter++;
}

public class Product
{
public Product()
{
}

public int ProductId { get; set; }
public string ProductName { get; set; }
public decimal? UnitPrice { get; set; }
public short? UnitsInStock { get; set; }
public bool Discontinued { get; set; }
public DateTime? CreatedAt { get; set; }
}

public class ChartSeriesData
{
public int Product1Sales { get; set; }
public double Product2Sales { get; set; }
public DateTime Year { get; set; }
public string SegmentName { get; set; }
}
}
Loading