当前位置:网站首页>Maui uses Masa blazor component library
Maui uses Masa blazor component library
2022-06-23 10:49:00 【dotnet9】
Last one ( Click here to read ) We did UI stay Web End (Blazor Server/Wasm) And the client (Windows/macOS/Android/iOS) share , I add Masa Blazor Reference to component library , And put the last few months to write Timestamp conversion Tools plus .

1. Pre knowledge
About Masa Blazor Please click on Masa Blazor Official website understand :
MASA Blazor
be based on Material Design and BlazorComponent Provides a standard base component library . Provide such as layout 、 Bullet frame standard 、Loading、 Preset components for standard scenarios such as global exception handling .
2. Reference to component library
Add reference of component library Masa Official website , Write it here Dotnet9 backstage Add records :
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
Add files ./MasaExtensions/MasaSetup.cs, The code is as follows :
using 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 }} There is only one line of critical code services.AddMasaBlazor();, The extension class is added for function extension , For the convenience of other projects ...
_Imports.razorintroduceMasa.BlazorNamespace
@using Masa.Blazor Is this 3 Step by step Dotnet9.WebApp Modification of .
2.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
modify wwwwroot/index.html file , Add the following styles ( Direct copy Masa.BlazorBlazor WebAssembly Resource files used )
<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 Blazorbuilder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });await builder.Build().RunAsync();- add to
Masa.BlazorResource file
Same as Dotnet9.MAUI
2.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 Blazorvar 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
modify Pages/_Layout.cshtml file , Add the following styles ( Copy Masa.BlazorBlazor Server Resource files used )
<!-- 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> Be careful :MAUI Blazor and Blazor WebAssembly Two projects are introduced Masa Blazor The code of the resource file is the same ,Blazor Server The main difference from the former two is materialdesignicons.min.css file :

Here's about Masa.Blazor The introduction of , Summarize the three key steps :
- 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
Doing it Blazor Server Version web site , There was an introduction to the development of timestamp function ( Click here to read ), The code is simple , I won't go into details here , No more water ....
4. summary
Masa.Blazor The component library has been added , And the timestamp function is restored , next step , Is to continue to build the website background , Use Masa.Blazor Build a framework .
- 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 )
边栏推荐
- Solve the problem of invalid audio autoplay
- 深潜Kotlin协程(十四):共享状态的问题
- argmax函数笔记-全是细节
- NOI OJ 1.4 01:判断数正负 C语言
- MySQL Basics - Notes
- MySQL-02. Understanding of indexes at work
- What does NFTs, Web3 and metauniverse mean for digital marketing?
- vector的介绍及使用
- NOI OJ 1.2 06:浮点数向零舍入
- Noi OJ 1.4 03: odd even judging C language
猜你喜欢
![[software and system security] heap overflow](/img/ca/1b98bcdf006f90cabf3e90e416f7f2.png)
[software and system security] heap overflow

flutter系列之:flutter中的Wrap

最简单DIY基于51单片机、PCA9685、IIC、云台的舵机集群控制程序

UWA new | real person real machine test new overseas model zone

深潜Kotlin协程(十四):共享状态的问题

连番承压之后,苹果或将大幅提高iPhone14的售价

Installation and use of binabsinspector, an open source binary file static vulnerability analysis tool

STM32F103ZET6单片机双串口互发程序设计与实现

经济小常识

Too helpless! Microsoft stopped selling AI emotion recognition and other technologies, saying frankly: "the law can not keep up with the development of AI"
随机推荐
STM32F103ZET6单片机双串口互发程序设计与实现
Implementing Domain Driven Design - using ABP framework - General guidelines
Noi OJ 1.4 03: odd even judging C language
详解判断大小端的方法
Installation and use of binabsinspector, an open source binary file static vulnerability analysis tool
MySQL-02. Understanding of indexes at work
Pycharm installation tutorial, super detailed
php 正则表达式
最简单DIY基于STM32的远程控制电脑系统②(无线遥杆+按键控制)
Noi OJ 1.3 20: power C language for computing 2
NOI OJ 1.4 01:判断数正负 C语言
安装typescript环境并开启VSCode自动监视编译ts文件为js文件
MySQL-02.工作中对索引的理解
Google Earth Engine(GEE)——GEDI L2A Vector Canopy Top Height (Ver
TTY drive frame
证券开户网上安全度高吗
ESP32-CAM无线监控智能网关的设计与实现
Noi OJ 1.3 09: circle related computing C language
C语言结构体字节对齐问题
What does NFTs, Web3 and metauniverse mean for digital marketing?