syncfusion-blazor-sidebar
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Syncfusion Blazor Sidebar Component
Syncfusion Blazor Sidebar组件实现指南
The Syncfusion Blazor Sidebar is a responsive navigation component that reserves screen space for navigation content. It supports multiple positioning modes, docking, state persistence, and integrates seamlessly with other Syncfusion components.
Syncfusion Blazor Sidebar是一款响应式导航组件,可为导航内容预留屏幕空间。它支持多种定位模式、停靠功能、状态持久化,并能与其他Syncfusion组件无缝集成。
When to Use This Skill
适用场景
Use this skill when you need to:
- Add a collapsible navigation sidebar to your Blazor application
- Control sidebar open/close state programmatically
- Enable responsive behavior based on screen resolution
- Show icons-only navigation (dock mode)
- Persist sidebar state across page navigation
- Display multiple sidebars with different positioning
- Target specific HTML elements for sidebar context
- Integrate ListView or TreeView components in sidebar
- Apply custom CSS styling to sidebar appearance
- Build responsive layouts in Blazor WebAssembly or .NET 8 apps
当你需要以下功能时,可以使用本技能:
- 为Blazor应用添加可折叠的导航侧边栏
- 以编程方式控制侧边栏的开合状态
- 基于屏幕分辨率实现响应式行为
- 显示仅含图标的导航(停靠模式)
- 在页面导航间持久化侧边栏状态
- 显示多个不同定位的侧边栏
- 为侧边栏指定特定HTML元素作为上下文
- 在侧边栏中集成ListView或TreeView组件
- 为侧边栏外观应用自定义CSS样式
- 在Blazor WebAssembly或.NET 8应用中构建响应式布局
Key Component Properties
核心组件属性
| Property | Purpose |
|---|---|
| Gets or sets a boolean value which indicates whether the Sidebar component's state is open or close. When the Sidebar type is set to |
| Sets sidebar width in pixels or percentage |
| Sidebar behavior: |
| Sidebar position: |
| Shows icons-only when collapsed (default: |
| Width of dock area in pixels |
| CSS media query for responsive behavior |
| Specific HTML element as sidebar context |
| Retains state in localStorage (default: |
| Overlay behind sidebar to prevent content interaction |
| Enables animation transitions while expanding or collapsing (default: |
| Displays sidebar in right-to-left direction for RTL languages (default: |
| 属性 | 用途 |
|---|---|
| 获取或设置布尔值,指示Sidebar组件的状态是展开还是收起。当Sidebar的Type设置为 |
| 设置侧边栏宽度,支持像素或百分比单位 |
| 侧边栏行为模式: |
| 侧边栏位置: |
| 收起时仅显示图标(默认值: |
| 停靠区域的宽度(像素单位) |
| 用于响应式行为的CSS媒体查询 |
| 指定作为侧边栏上下文的HTML元素 |
| 在localStorage中保留状态(默认值: |
| 在侧边栏后方显示遮罩层,阻止底层内容交互 |
| 展开或收起时启用动画过渡(默认值: |
| 为RTL语言显示从右到左的侧边栏(默认值: |
Documentation and Navigation Guide
文档与导航指南
Getting Started
入门指南
📄 Read: references/getting-started.md
- Installation across Visual Studio, VS Code, and .NET CLI
- NuGet package setup (Syncfusion.Blazor.Navigations, Syncfusion.Blazor.Themes)
- Namespace imports and service registration
- Theme stylesheet and script references
- Basic component rendering
📄 阅读: references/getting-started.md
- Visual Studio、VS Code和.NET CLI环境下的安装步骤
- NuGet包配置(Syncfusion.Blazor.Navigations、Syncfusion.Blazor.Themes)
- 命名空间导入与服务注册
- 主题样式表与脚本引用
- 基础组件渲染
Web App Setup (.NET 8)
.NET 8 Web应用设置
📄 Read: references/web-app-setup.md
- Blazor Web App project creation
- Interactive render modes (Auto, Server, WebAssembly)
- Package installation for client projects
- Stylesheet and script references in App.razor
- Render mode directive usage
📄 阅读: references/web-app-setup.md
- Blazor Web App项目创建
- 交互式渲染模式(Auto、Server、WebAssembly)
- 客户端项目的包安装
- App.razor中的样式表与脚本引用
- 渲染模式指令的使用
Open/Close Control
开合控制
📄 Read: references/open-close-control.md
- property and two-way binding with
IsOpen@bind-IsOpen - Toggle methods for programmatic control
- Button-based sidebar toggling
- Combining multiple open/close triggers and standard event handling
📄 阅读: references/open-close-control.md
- 属性及
IsOpen双向绑定@bind-IsOpen - 用于编程控制的切换方法
- 基于按钮的侧边栏切换
- 组合多个开合触发器与标准事件处理
Responsive & Docking Features
响应式与停靠功能
📄 Read: references/responsive-docking.md
- property for responsive behavior
MediaQuery - property for icon-only navigation mode
EnableDock - to control icon area width
DockSize - Icon styling and font-face setup
- Docking with ListItems and icon management
📄 阅读: references/responsive-docking.md
- 用于响应式行为的属性
MediaQuery - 用于仅图标导航模式的属性
EnableDock - 控制图标区域宽度的
DockSize - 图标样式与字体设置
- 与列表项结合的停靠功能及图标管理
State Persistence & Target Context
状态持久化与目标上下文
📄 Read: references/state-persistence-targets.md
- for localStorage support
EnablePersistence - ID requirement for persistence to work
- property for sidebar context
Target - Applying sidebar to specific HTML elements
- Toolbar and AppBar integration
📄 阅读: references/state-persistence-targets.md
- 支持localStorage的
EnablePersistence - 持久化功能生效所需的ID要求
- 用于侧边栏上下文的属性
Target - 将侧边栏应用于特定HTML元素
- 工具栏与AppBar集成
Styling & Animation
样式与动画
📄 Read: references/styling-customization.md
- Animation control using property
Animate - RTL (right-to-left) support using property
EnableRtl - CSS transitions and custom animation effects
- State-based styling and visual customization
- Backdrop customization and dock styling
📄 阅读: references/styling-customization.md
- 使用属性控制动画
Animate - 使用属性支持RTL(从右到左)布局
EnableRtl - CSS过渡与自定义动画效果
- 基于状态的样式与视觉定制
- 遮罩层定制与停靠样式
Multiple Sidebars
多侧边栏配置
📄 Read: references/multiple-sidebars.md
- Managing multiple sidebar instances
- property (Left/Right)
Position - class for multi-sidebar layouts
e-main-content - Left and right sidebar toggling
- Coordinating multiple sidebar states
📄 阅读: references/multiple-sidebars.md
- 管理多个侧边栏实例
- 属性(左/右)
Position - 用于多侧边栏布局的类
e-main-content - 左右侧边栏的切换
- 协调多个侧边栏的状态
Content Integration
内容集成
📄 Read: references/content-integration.md
- Integrating ListView component in sidebar
- ListViewFieldSettings configuration
- TreeView integration for hierarchical menus
- Toolbar component integration
- MainLayout integration in .NET 8 apps
📄 阅读: references/content-integration.md
- 在侧边栏中集成ListView组件
- ListViewFieldSettings配置
- 用于层级菜单的TreeView集成
- Toolbar组件集成
- .NET 8应用中的MainLayout集成
API Reference
API参考
📄 Read: references/api-reference.md
- Complete API documentation for SfSidebar component
- All 22 properties with descriptions and accepted values
- Methods and their return types
- Complete event system (Changed, Created, Destroyed, IsOpenChanged, OnClose, OnOpen)
- Event arguments (ChangeEventArgs, EventArgs)
- SfSidebarContainer documentation
- 9+ comprehensive usage examples with code
- Property use cases with practical implementations
📄 阅读: references/api-reference.md
- SfSidebar组件的完整API文档
- 所有22个属性的描述与可接受值
- 方法及其返回类型
- 完整事件系统(Changed、Created、Destroyed、IsOpenChanged、OnClose、OnOpen)
- 事件参数(ChangeEventArgs、EventArgs)
- SfSidebarContainer文档
- 9+个综合使用示例及代码
- 属性的实际应用场景
Quick Start Example
快速入门示例
blazor
@using Syncfusion.Blazor.Navigations
@using Syncfusion.Blazor.Buttons
<SfSidebar @ref="sidebarObj" Width="250px" @bind-IsOpen="SidebarToggle">
<ChildContent>
<div style="text-align: center; padding: 3rem;">
<p>Sidebar Content</p>
<SfButton @onclick="Close" CssClass="e-btn">Close</SfButton>
</div>
</ChildContent>
</SfSidebar>
<div style="padding: 3rem;">
<div>Main Content</div>
<SfButton @onclick="Toggle" IsToggle="true">Toggle Sidebar</SfButton>
</div>
@code {
SfSidebar sidebarObj;
public bool SidebarToggle = false;
public void Toggle() => SidebarToggle = !SidebarToggle;
public void Close() => SidebarToggle = false;
}blazor
@using Syncfusion.Blazor.Navigations
@using Syncfusion.Blazor.Buttons
<SfSidebar @ref="sidebarObj" Width="250px" @bind-IsOpen="SidebarToggle">
<ChildContent>
<div style="text-align: center; padding: 3rem;">
<p>Sidebar Content</p>
<SfButton @onclick="Close" CssClass="e-btn">Close</SfButton>
</div>
</ChildContent>
</SfSidebar>
<div style="padding: 3rem;">
<div>Main Content</div>
<SfButton @onclick="Toggle" IsToggle="true">Toggle Sidebar</SfButton>
</div>
@code {
SfSidebar sidebarObj;
public bool SidebarToggle = false;
public void Toggle() => SidebarToggle = !SidebarToggle;
public void Close() => SidebarToggle = false;
}Common Implementation Patterns
常见实现模式
Pattern 1: Basic Toggle Sidebar
模式1:基础切换侧边栏
Use property with button click to show/hide sidebar.
IsOpen使用属性结合按钮点击来显示/隐藏侧边栏。
IsOpenPattern 2: Responsive Sidebar
模式2:响应式侧边栏
Use to automatically hide sidebar on mobile and show on desktop.
MediaQuery使用在移动端自动隐藏侧边栏,在桌面端自动显示。
MediaQueryPattern 3: Docked Navigation
模式3:停靠式导航
Use with for icon-only navigation that expands on hover/click.
EnableDockDockSize结合与实现仅图标导航, hover/点击时展开。
EnableDockDockSizePattern 4: Persistent State
模式4:持久化状态
Use + unique to remember sidebar state across page navigation.
EnablePersistenceID使用 + 唯一在页面导航间记住侧边栏状态。
EnablePersistenceIDPattern 5: Target Property Behavior
模式5:Target属性行为
- Implicit (Default): No property → sidebar targets next sibling element automatically
Target - Explicit (Advanced): → requires inner wrapper
Target=".selector"for CSS transforms<div> - ✓ Use implicit for most cases | Use explicit only for scoped layout control
- See State Persistence & Target Context for detailed patterns
- 隐式(默认): 未设置属性 → 侧边栏自动以相邻的下一个元素为目标
Target - 显式(进阶): → 需要内部包装
Target=".selector"以支持CSS变换<div> - ✓ 大多数场景使用隐式模式 | 仅在需要作用域布局控制时使用显式模式
- 详细模式请参考状态持久化与目标上下文
Pattern 6: Sidebar with Menu
模式6:带菜单的侧边栏
Combine with ListView or TreeView for structured navigation menus.
与ListView或TreeView结合构建结构化导航菜单。
Pattern 7: Multiple Sidebars
模式7:多侧边栏布局
Use property with left/right sidebars flanking main content.
PositionNext Steps:
- Choose your platform: WebAssembly or .NET 8 Web App
- Follow the Getting Started guide for installation
- Select features from the navigation guide above
- Implement your sidebar with appropriate styling
For detailed examples and advanced scenarios, refer to individual reference files.
使用属性在主内容两侧配置左右侧边栏。
Position下一步:
- 选择平台:WebAssembly或.NET 8 Web App
- 遵循入门指南完成安装
- 从上方导航指南中选择所需功能
- 实现侧边栏并应用合适的样式
如需详细示例和进阶场景,请参考各个参考文档。