当前位置:网站首页>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 )
边栏推荐
- Five SQL functions for operation date that must be known in SQL tutorial
- JVM easy start-01
- Unity technical manual - limit velocity over lifetime sub module and inherit velocity sub module
- How to solve the problem that easycvr does not display the interface when RTMP streaming is used?
- Solve the problem that Preview PDF cannot be downloaded
- web技术分享| 【高德地图】实现自定义的轨迹回放
- 图片存储--引用
- EasyCVR使用RTMP推流时不显示界面如何解决?
- 线程池在项目中使用的心得体会
- Noi OJ 1.4 01: positive and negative C language
猜你喜欢

Mathematical analysis_ Notes_ Chapter 2: real and plural numbers

ESP32-CAM、ESP8266、WIFI、蓝牙、单片机、热点创建嵌入式DNS服务器

经济小常识

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

Solve the problem that Preview PDF cannot be downloaded

开源二进制文件静态漏洞分析工具BinAbsInspector安装使用

解决预览pdf不能下载的问题

技术创造价值,手把手教你薅羊毛篇

新派科技美学、原生物联网操作系统重塑全屋智能

当 Pandas 遇见 SQL,一个强大的工具库诞生了
随机推荐
新派科技美学、原生物联网操作系统重塑全屋智能
How to write a literature review? What should I do if I don't have a clue?
ESP32-CAM、ESP8266、WIFI、蓝牙、单片机、热点创建嵌入式DNS服务器
证券开户网上安全度高吗
Stm32f1 and stm32subeide programming example - infrared tracking sensor driver
Explain in detail the method of judging the size end
MySQL-01.工作中数据库优化和explain字段知识的总结
Installation and use of binabsinspector, an open source binary file static vulnerability analysis tool
2021-05-11 abstract class
开源二进制文件静态漏洞分析工具BinAbsInspector安装使用
为什么poll/select在open时要使用非阻塞NONBLOCK
深潜Kotlin协程(十四):共享状态的问题
list的介绍及使用
NOI OJ 1.3 04:带余除法 C语言
Noi OJ 1.3 17: calculating triangle area C language
实现常用C语言字符串处理函数
New technology aesthetics and original biological networking operating system reshape the whole house intelligence
What does NFTs, Web3 and metauniverse mean for digital marketing?
Five SQL functions for operation date that must be known in SQL tutorial
圖片存儲--引用