Skip to content

Commit 037bfe3

Browse files
Merge pull request #1878 from syncfusion-content/989310-CherryPick
989310: Added UG content for getting started with Blazor Hybrid MAUI app
2 parents 088fdf6 + 97b8464 commit 037bfe3

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-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: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
layout: post
3+
title: Getting Started with .NET MAUI Blazor Hybrid App | Syncfusion
4+
description: Learn how to get started with .NET MAUI Blazor Hybrid App using the Syncfusion Spreadsheet component.
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+
{% tabs %}
38+
{% highlight xaml tabtitle="MainPage.xaml" %}
39+
40+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
41+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
42+
xmlns:local="clr-namespace:MauiApp1"
43+
x:Class="MauiApp1.MainPage">
44+
45+
<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
46+
<BlazorWebView.RootComponents>
47+
<RootComponent Selector="#app" ComponentType="{x:Type local:Components.Routes}" />
48+
</BlazorWebView.RootComponents>
49+
</BlazorWebView>
50+
51+
</ContentPage>
52+
53+
{% endhighlight %}
54+
{% endtabs %}
55+
56+
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.
57+
58+
59+
## Install Syncfusion Blazor Spreadsheet and Themes NuGet in the App
60+
61+
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.
62+
63+
{% tabs %}
64+
{% highlight C# tabtitle="Package Manager" %}
65+
66+
Install-Package Syncfusion.Blazor.Spreadsheet -Version {{ site.releaseversion }}
67+
Install-Package Syncfusion.Blazor.Themes -Version {{ site.releaseversion }}
68+
69+
{% endhighlight %}
70+
{% endtabs %}
71+
72+
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.
73+
74+
## Register Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Service
75+
76+
Open **~/_Imports.razor** file and import the `Syncfusion.Blazor` and `Syncfusion.Blazor.Spreadsheet` namespaces.
77+
78+
{% tabs %}
79+
{% highlight razor tabtitle="~/_Imports.razor" %}
80+
81+
@using Syncfusion.Blazor
82+
@using Syncfusion.Blazor.Spreadsheet
83+
84+
{% endhighlight %}
85+
{% endtabs %}
86+
87+
Next, register the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor Service in the MauiProgram.cs file of the MAUI Blazor App.
88+
89+
{% tabs %}
90+
{% highlight C# tabtitle="~/MauiProgram.cs" %}
91+
92+
using Syncfusion.Blazor;
93+
....
94+
builder.Services.AddSyncfusionBlazor();
95+
....
96+
97+
{% endhighlight %}
98+
{% endtabs %}
99+
100+
## Add stylesheet and script resources
101+
102+
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.
103+
104+
```html
105+
<head>
106+
....
107+
<link href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" />
108+
<script src="_content/Syncfusion.Blazor.Spreadsheet/scripts/syncfusion-blazor-spreadsheet.min.js" type="text/javascript"></script>
109+
</head>
110+
```
111+
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.
112+
113+
## Add Blazor Spreadsheet component
114+
115+
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.
116+
117+
{% tabs %}
118+
{% highlight razor %}
119+
120+
<SfSpreadsheet DataSource="@DataSourceBytes">
121+
<SpreadsheetRibbon></SpreadsheetRibbon>
122+
</SfSpreadsheet>
123+
124+
@code {
125+
public byte[] DataSourceBytes { get; set; }
126+
127+
protected override void OnInitialized()
128+
{
129+
string filePath = "wwwroot/Sample.xlsx";
130+
DataSourceBytes = File.ReadAllBytes(filePath);
131+
}
132+
}
133+
134+
{% endhighlight %}
135+
{% endtabs %}

0 commit comments

Comments
 (0)