syncfusion-blazor-common
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSyncfusion Blazor Getting Started
Syncfusion Blazor 入门指南
Setup and configuration guide for Syncfusion Blazor components in Blazor Web Apps.
Blazor Web Apps中Syncfusion Blazor组件的设置与配置指南。
When to Use
适用场景
Use this skill when you need to:
- Set up a new Blazor project with Syncfusion Blazor components
- Create a Blazor Web App with specific .NET version targeting (net8.0, net9.0, net10.0, etc.)
- Add Syncfusion components (Grid, Button, etc.) with features based on context
- Optimize script loading with static assets or CDN
- Set up bUnit testing for Syncfusion components
当你需要以下操作时使用本技能:
- 使用Syncfusion Blazor组件搭建新的Blazor项目
- 创建针对特定.NET版本(net8.0、net9.0、net10.0等)的Blazor Web App
- 根据上下文添加带有特定功能的Syncfusion组件(Grid、Button等)
- 通过静态资源或CDN优化脚本加载
- 为Syncfusion组件设置bUnit测试
Quick Reference
快速参考
- Getting Started: See getting-started.md for full project setup steps
- Scripts & CDN: See add-script-reference-and-cdn.md for script loading options
- bUnit Testing: See bunit-setup.md for unit testing setup
- Localization & Globalization: See localization-globalization.md for culture and localization setup
- 入门指南:查看getting-started.md获取完整的项目设置步骤
- 脚本与CDN:查看add-script-reference-and-cdn.md了解脚本加载选项
- bUnit测试:查看bunit-setup.md了解单元测试设置
- 本地化与全球化:查看localization-globalization.md了解文化与本地化设置
Prerequisites
前提条件
- .NET 8+ SDK
- Blazor Web App project
- Syncfusion account (free trial)
- NuGet package access
- .NET 8+ SDK
- Blazor Web App项目
- Syncfusion账户(免费试用)
- NuGet包访问权限
1. Getting Started
1. 入门指南
Detailed guide: getting-started.md
详细指南:getting-started.md
Quick Setup
快速设置
- Create Blazor Web App with your chosen render mode and explicit .NET version (e.g., )
.NET 10 - Install +
Syncfusion.Blazor.GridNuGet packages. All individual packages are listed hereSyncfusion.Blazor.Themes - Add and relevant component namespaces to
@using Syncfusion.Blazor_Imports.razor - Register in
builder.Services.AddSyncfusionBlazor()Program.cs - Add theme CSS and script references to
App.razor - Use Syncfusion components in your pages
Key Rule: For Auto/WASM modes → register in both server and client projects
Important: Always specify the target .NET framework version when creating projects to ensure compatibility
- 创建带有所选渲染模式和指定.NET版本(例如)的Blazor Web App
.NET 10 - 安装+
Syncfusion.Blazor.GridNuGet包。所有独立包的列表请查看此处Syncfusion.Blazor.Themes - 在中添加
_Imports.razor及相关组件的命名空间@using Syncfusion.Blazor - 在中注册
Program.csbuilder.Services.AddSyncfusionBlazor() - 在中添加主题CSS和脚本引用
App.razor - 在页面中使用Syncfusion组件
关键规则:对于Auto/WASM模式 → 在服务器和客户端项目中都要注册
重要提示:创建项目时始终指定目标.NET框架版本,以确保兼容性
Quick Start Options
快速入门选项
- Blazor Playground: Browser-based, no local install
- Template Studio: Pre-configured VS/VS Code project templates
- Blazor Playground:基于浏览器,无需本地安装
- Template Studio:预配置的VS/VS Code项目模板
2. Script References and CDN
2. 脚本引用与CDN
Detailed guide: add-script-reference-and-cdn.md
详细指南:add-script-reference-and-cdn.md
Script Loading Options
脚本加载选项
| Method | Best For |
|---|---|
| Static Web Assets (Recommended) | Optimal performance, offline support |
| CDN | Cloud-hosted, quick setup |
| Individual Scripts | Minimal component usage |
| 方法 | 最佳适用场景 |
|---|---|
| 静态Web资源(推荐) | 最佳性能,支持离线使用 |
| CDN | 云托管,快速设置 |
| 独立脚本 | 仅使用少量组件时 |
3. bUnit Testing
3. bUnit测试
Detailed guide: bunit-setup.md
Unit test Syncfusion Blazor components with bUnit.
详细指南:bunit-setup.md
使用bUnit对Syncfusion Blazor组件进行单元测试。
Required Setup
必要设置
Install NuGet package, then register in each test:
bunitcsharp
using var ctx = new TestContext();
ctx.Services.AddSyncfusionBlazor()
.Replace(ServiceDescriptor.Transient<IComponentActivator, SfComponentActivator>());
ctx.Services.AddOptions();安装 NuGet包,然后在每个测试中注册:
bunitcsharp
using var ctx = new TestContext();
ctx.Services.AddSyncfusionBlazor()
.Replace(ServiceDescriptor.Transient<IComponentActivator, SfComponentActivator>());
ctx.Services.AddOptions();Test Pattern
测试模式
- → render
RenderComponent<TPage>() - → locate
FindComponent<SfButton>() - → interact
.Click() - → assert
MarkupMatches(...)
Works with xUnit and NUnit (use for NUnit to avoid naming conflicts)
Bunit.TestContext- → 渲染
RenderComponent<TPage>() - → 定位
FindComponent<SfButton>() - → 交互
.Click() - → 断言
MarkupMatches(...)
适用于xUnit和NUnit(NUnit使用以避免命名冲突)
Bunit.TestContext4. Localization and Globalization
4. 本地化与全球化
Detailed guide: localization-globalization.md
Configure multi-language support and culture-specific formatting for Syncfusion Blazor components.
详细指南:localization-globalization.md
为Syncfusion Blazor组件配置多语言支持和特定文化的格式设置。
Key Concepts
核心概念
- Internationalization (i18n): Parsing and formatting dates, times, numbers, and currencies
- Localization (l10n): Adding culture-specific customizations and translating UI text
- Globalization: Combines both i18n and l10n
- 国际化(i18n):解析和格式化日期、时间、数字及货币
- 本地化(l10n):添加特定文化的自定义设置并翻译UI文本
- 全球化:结合i18n和l10n两者
Quick Setup
快速设置
- Download and add culture-based resource files from GitHub - ASK PERMISSION BEFORE DOWNLOAD THIS
.resx - Create a class implementing
SyncfusionLocalizerISyncfusionStringLocalizer - Register in :
Program.cscsharpbuilder.Services.AddSyncfusionBlazor(); builder.Services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SyncfusionLocalizer)); - Set culture statically or dynamically (server, WebAssembly, or MAUI apps)
- Create a component for dynamic culture selection
CultureSwitcher
- 从GitHub下载并添加基于文化的资源文件 - 下载前请征得许可
.resx - 创建实现接口的
ISyncfusionStringLocalizer类SyncfusionLocalizer - 在中注册:
Program.cscsharpbuilder.Services.AddSyncfusionBlazor(); builder.Services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SyncfusionLocalizer)); - 静态或动态设置文化(服务器、WebAssembly或MAUI应用)
- 创建组件以实现动态文化选择
CultureSwitcher