Skip to content

Commit 86565c9

Browse files
989310: Added UG content for getting started with Blazor Hybrid MAUI app
1 parent 9a17d5e commit 86565c9

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

Document-Processing-toc.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5043,6 +5043,7 @@
50435043
<ul>
50445044
<li><a href="/document-processing/excel/spreadsheet/blazor/getting-started-webapp">Blazor Web App</a></li>
50455045
<li><a href="/document-processing/excel/spreadsheet/blazor/getting-started">Blazor WASM App</a></li>
5046+
<li><a href="/document-processing/excel/spreadsheet/blazor/blazor-hybrid-maui-app">Blazor Hybrid MAUI App</a></li>
50465047
</ul>
50475048
</li>
50485049
<li><a href="/document-processing/excel/spreadsheet/blazor/open-and-save">Open and Save</a></li>
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
layout: post
3+
title: Getting Started with .NET MAUI Blazor Hybrid App | Syncfusion
4+
description: Learn how to build apps using .NET MAUI Blazor Hybrid App with the Syncfusion spreadsheet component. This guide helps you set up, create, and run cross-platform applications quickly.
5+
platform: document-processing
6+
control: Spreadsheet
7+
documentation: ug
8+
---
9+
10+
# Getting Started with .NET MAUI Blazor Hybrid App
11+
12+
This section explains how to create and run a .NET Multi-platform Blazor App UI (.NET MAUI with Blazor Hybrid App) using Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Spreadsheet component.
13+
14+
## What is a .NET MAUI Blazor Hybrid App?
15+
16+
A .NET MAUI Blazor Hybrid App is a .NET MAUI application where a Blazor Web App is hosted in the .NET MAUI app using the BlazorWebView control. This enables a Blazor Web App to integrate with platform features and UI controls. The BlazorWebView can be added to any page of a .NET MAUI app and pointed to the root of the Blazor app. The Blazor components run in the .NET process and render the web UI to an embedded web view control. .NET MAUI Blazor apps can run on all platforms supported by .NET MAUI.
17+
18+
Visual Studio provides the **.NET MAUI Blazor Hybrid App** template to create .NET MAUI Blazor Hybrid Apps.
19+
20+
## Prerequisites
21+
22+
- .NET SDK 8.0 or above
23+
- Visual Studio 2022 17.1 or above with the required workloads:
24+
- [Mobile development with .NET](https://learn.microsoft.com/en-us/dotnet/maui/get-started/installation?view=net-maui-10.0&tabs=visual-studio)
25+
- ASP.NET and web development
26+
27+
## Create a new .NET MAUI Blazor App in Visual Studio
28+
29+
Create a **.NET MAUI Blazor Hybrid App** using Visual Studio via [Microsoft Templates](https://learn.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/maui?view=aspnetcore-8.0).
30+
31+
## BlazorWebView in .NET MAUI Blazor App
32+
33+
The above steps create a multi-targeted .NET MAUI Blazor app that can be deployed to Android, iOS, macOS, and Windows.
34+
35+
In `MainPage.xaml`, the `BlazorWebView` is added and points to the root of the Blazor app. The root Blazor component for the app is in `Routes.razor`, which Razor compiles into a type named `Routes` in the application’s root namespace.
36+
37+
38+
{% tabs %}
39+
{% highlight xaml tabtitle="MainPage.xaml" %}
40+
41+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
42+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
43+
xmlns:local="clr-namespace:MauiApp1"
44+
x:Class="MauiApp1.MainPage">
45+
46+
<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
47+
<BlazorWebView.RootComponents>
48+
<RootComponent Selector="#app" ComponentType="{x:Type local:Components.Routes}" />
49+
</BlazorWebView.RootComponents>
50+
</BlazorWebView>
51+
52+
</ContentPage>
53+
54+
{% endhighlight %}
55+
{% endtabs %}
56+
57+
For more details, refer to the [Create a .NET MAUI Blazor app](https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/blazorwebview?view=net-maui-10.0#create-a-net-maui-blazor-app) topic.
58+
59+
60+
## Install Syncfusion Blazor Spreadsheet and Themes NuGet in the App
61+
62+
To add the Blazor Spreadsheet component to the app, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), then search for and install [Syncfusion.Blazor.Spreadsheet](https://www.nuget.org/packages/Syncfusion.Blazor.Spreadsheet) and [Syncfusion.Blazor.Themes](https://www.nuget.org/packages/Syncfusion.Blazor.Themes/). Alternatively, use the following Package Manager commands.
63+
64+
{% tabs %}
65+
{% highlight C# tabtitle="Package Manager" %}
66+
67+
Install-Package Syncfusion.Blazor.Spreadsheet -Version {{ site.releaseversion }}
68+
Install-Package Syncfusion.Blazor.Themes -Version {{ site.releaseversion }}
69+
70+
{% endhighlight %}
71+
{% endtabs %}
72+
73+
N> Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor components are available in [nuget.org](https://www.nuget.org/packages?q=syncfusion.blazor). Refer to [NuGet packages](https://blazor.syncfusion.com/documentation/nuget-packages) topic for available NuGet packages list with component details.
74+
75+
## Register Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Service
76+
77+
Open **~/_Imports.razor** file and import the `Syncfusion.Blazor` and `Syncfusion.Blazor.Spreadsheet` namespaces.
78+
79+
{% tabs %}
80+
{% highlight razor tabtitle="~/_Imports.razor" %}
81+
82+
@using Syncfusion.Blazor
83+
@using Syncfusion.Blazor.Spreadsheet
84+
85+
{% endhighlight %}
86+
{% endtabs %}
87+
88+
Next, register the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Service in the MauiProgram.cs file of the MAUI Blazor App.
89+
90+
{% tabs %}
91+
{% highlight C# tabtitle="~/MauiProgram.cs" %}
92+
93+
using Syncfusion.Blazor;
94+
....
95+
builder.Services.AddSyncfusionBlazor();
96+
....
97+
98+
{% endhighlight %}
99+
{% endtabs %}
100+
101+
## Add stylesheet and script resources
102+
103+
The theme stylesheet and script can be accessed from NuGet through [Static Web Assets](https://blazor.syncfusion.com/documentation/appearance/themes#static-web-assets). Include the stylesheet and script references in the `<head>` of the **~wwwroot/index.html** file.
104+
105+
```html
106+
<head>
107+
....
108+
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
109+
<script src="_content/Syncfusion.Blazor.Spreadsheet/scripts/syncfusion-blazor-spreadsheet.min.js" type="text/javascript"></script>
110+
</head>
111+
```
112+
N> Check out the [Blazor Themes](https://blazor.syncfusion.com/documentation/appearance/themes) topic to discover various methods ([Static Web Assets](https://blazor.syncfusion.com/documentation/appearance/themes#static-web-assets), [CDN](https://blazor.syncfusion.com/documentation/appearance/themes#cdn-reference), and [CRG](https://blazor.syncfusion.com/documentation/common/custom-resource-generator)) for referencing themes in your Blazor application. Also, check out the [Adding Script Reference](https://blazor.syncfusion.com/documentation/common/adding-script-references) topic to learn different approaches for adding script references in your Blazor application.
113+
114+
## Add Blazor Spreadsheet component
115+
116+
Add the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Spreadsheet component in any Razor file. In this example, the Spreadsheet component is added to the ~/Home.razor page under the **~/Components/Pages** folder.
117+
118+
{% tabs %}
119+
{% highlight razor %}
120+
121+
<SfSpreadsheet DataSource="@DataSourceBytes">
122+
<SpreadsheetRibbon></SpreadsheetRibbon>
123+
</SfSpreadsheet>
124+
125+
@code {
126+
public byte[] DataSourceBytes { get; set; }
127+
128+
protected override void OnInitialized()
129+
{
130+
string filePath = "wwwroot/Sample.xlsx";
131+
DataSourceBytes = File.ReadAllBytes(filePath);
132+
}
133+
}
134+
135+
{% endhighlight %}
136+
{% endtabs %}

0 commit comments

Comments
 (0)