当前位置:网站首页>Maui uses Masa blazor component library
Maui uses Masa blazor component library
2022-06-22 14:16:00 【InfoQ】

1. Pre knowledge
2. Reference to component library
2.1 UI Modification of shared library -
Dotnet9.WebApp
- UI Shared library
Dotnet9.WebAppadd toMaas.Blazorpackage , Just today (21 Number )Masa Released0.5.0-preview.3edition , We download and use :
Install-Package Masa.Blazor -Version 0.5.0-preview.3

- encapsulation
Maas.BlazorComponent references
./MasaExtensions/MasaSetup.csusing Microsoft.Extensions.DependencyInjection;
namespace Dotnet9.WebApp.MasaExtensions;
public static class MasaSetup
{
public static void AddMasaSetup(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddMasaBlazor(); // This key code
}
}
services.AddMasaBlazor();_Imports.razorintroduceMasa.BlazorNamespace
@using Masa.Blazor
Dotnet9.WebApp2.2 Cross platform project modification -Dotnet9.MAUI
- modify
MauiProgram.csfile , Add the extension method encapsulated aboveAddMasaSetup():
using Dotnet9.WebApp.MasaExtensions; // The first 1 It's about : Add this namespace
namespace Dotnet9.MAUI;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); });
builder.Services.AddMauiBlazorWebView();
#if DEBUG
builder.Services.AddBlazorWebViewDeveloperTools();
#endif
builder.Services.AddMasaSetup(); // The first 2 Outside : Add an extension method to introduce Masa Blazor
return builder.Build();
}
}
- add to
Masa.BlazorResource file
wwwwroot/index.htmlBlazor WebAssembly<link href="_content/Masa.Blazor/css/masa-blazor.css" rel="stylesheet" />
<link href="_content/Masa.Blazor/css/masa-extend-blazor.css" rel="stylesheet" />
<link href="https://cdn.masastack.com/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.masastack.com/npm/materialicons/materialicons.css" rel="stylesheet">
<link href="https://cdn.masastack.com/npm/fontawesome/v5.0.13/css/all.css" rel="stylesheet">
<script src="_content/BlazorComponent/js/blazor-component.js"></script>
2.3 Blazor WebAssembly Project modification -Dotnet9.Wasm
- modify
Program.csfile , Add the extension method encapsulated aboveAddMasaSetup():
using Dotnet9.WebApp;
using Dotnet9.WebApp.MasaExtensions; // The first 1 It's about : Add this namespace
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<Main>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddMasaSetup(); // The first 2 Outside : Add an extension method to introduce Masa Blazor
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();
- add to
Masa.BlazorResource file
Dotnet9.MAUI2.4 Blazor Server Project modification -Dotnet9.Server
- modify
Program.csfile , Add the extension method encapsulated aboveAddMasaSetup():
using Dotnet9.WebApp.MasaExtensions; // The first 1 It's about : Add this namespace
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddMasaSetup(); // The first 2 Outside : Add an extension method to introduce Masa Blazor
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
- add to
Masa.BlazorResource file
Pages/_Layout.cshtmlBlazor Server<!-- masa blazor css style -->
<link href="_content/Masa.Blazor/css/masa-blazor.css" rel="stylesheet" />
<link href="_content/Masa.Blazor/css/masa-extend-blazor.css" rel="stylesheet" />
<!--icon file,import need to use-->
<link href="https://cdn.masastack.com/npm/@("@mdi")/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.masastack.com/npm/materialicons/materialicons.css" rel="stylesheet">
<link href="https://cdn.masastack.com/npm/fontawesome/v5.0.13/css/all.css" rel="stylesheet">
<!--js(should lay the end of file)-->
<script src="_content/BlazorComponent/js/blazor-component.js"></script>
materialdesignicons.min.css
Masa.Blazor- add to
Masa.BlazorNuget package :Install-Package Masa.Blazor;
Masa.BlazorComponent registration use :services.AddMasaBlazor();;
- add to
Masa.BlazorResource file :Wasm yeswwwwroot/index.html, blazor server yes_Layout.cshtml, Note the difference between adding resource files .
3. Add timestamp function
4. summary
Masa.BlazorMasa.Blazor- this paper Blazor Server Site Preview :https://server.dotnet9.com/
- this paper Blazor Wasm Site Preview :https://wasm.dotnet9.com/
- MAUI(Android\Windows\macOS\iOS) preview :https://github.com/dotnet9/Dotnet9/tree/develop/src/Dotnet9.MAUI( No release document is made , You need to compile the source code yourself )
边栏推荐
- 12306 ticket grabbing tutorial
- How do I open an account on my mobile phone? Is it safe to open an account online?
- 金融应用如何解决金额精度问题(以Quorum、golang为例)
- Record of problems encountered in dual network card binding
- Z-Score和deltf/f有什么区别?
- Eureka的InstanceInfoReplicator类(服务注册辅助类)
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- JS高级程序设计第 4 版:迭代器的学习
- Vcip2021: super resolution using decoded information
- 怎样在手机上开户?网上开户安全么?
猜你喜欢

Flink状态管理

After several years of writing at CSDN, I published "the first book". Thank you!

Database employment consulting system for your help

HW is around the corner. Can't you read the danger message?

hw在即,你还不会看危险报文?
MySQL如何让一个表中可以有多个自增列

Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things
How MySQL enables multiple auto incrementing columns in a table

Cve-2022-22965 reappearance

Configuring cplex12.4 tutorial in VS2010
随机推荐
芯片硅片与流片技术
论文专利博客写作总结
Traffic replication in istio Service Grid
软件项目验收测试范围和流程,这些你都知道吗?
Implementation of redis+caffeine two-level cache
My suggestions on SAP ABAP transformation
Implementation of connecting SQL server to Oracle server_ Including query implementation
Database employment consulting system for your help
如何给VR全景作品添加遮罩?作用是什么?
Offline physical stores combined with VR panorama make virtual shopping more realistic
Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things
Screenshot of the uniapp app and save it locally
Tianrun cloud is about to be listed: VC tycoon Tian Suning significantly reduces his holdings and is expected to cash out HK $260million
A simple scientific research secret
Oracle user space statistics
VR panoramic shooting breaks the deadlock of traditional propaganda that wild geese pass without leaving traces
Consolidation of common functions of numpy Library
Which securities company is good for retail investors to open an account? Is it safe to open a mobile account?
Eureka的InstanceInfoReplicator类(服务注册辅助类)
Rongyun: let the bank go to the "cloud" easily