syncfusion-wpf-tabbedwindow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implementing Syncfusion WPF Tabbed Windows

实现Syncfusion WPF Tabbed Window

A comprehensive guide for implementing the Syncfusion WPF Tabbed Window control, which combines
SfChromelessWindow
with
SfTabControl
to create professional document-based applications with advanced tab management, tear-off windows, and cross-window tab merging capabilities.
本文是关于实现Syncfusion WPF Tabbed Window控件的综合指南,该控件结合
SfChromelessWindow
SfTabControl
,可创建具备高级标签管理、可拖离窗口和跨窗口标签合并功能的专业文档类应用程序。

When to Use This Skill

适用场景

Use this skill when you need to:
  • Build document-based applications with multiple documents in tabs (similar to Visual Studio, Visual Studio Code, or modern web browsers)
  • Implement browser-style tab interfaces with integrated chrome and tab navigation
  • Create multi-document interfaces (MDI) with modern tabbed layouts instead of traditional MDI windows
  • Enable tear-off functionality allowing users to drag tabs out to create floating windows
  • Support tab merging between multiple windows through drag-and-drop operations
  • Implement dynamic tab management with add/close/select operations and new tab buttons
  • Build MVVM-compatible tabbed interfaces with data binding to observable collections
  • Create professional desktop applications requiring flexible workspace organization
  • Implement code editors, document viewers, or content management tools with tabbed navigation
  • Support multiple window layouts with tabs integrated into window chrome or as content
This skill covers all aspects of the Tabbed Window control including setup, window modes, tab management, data binding, tear-off windows, tab merging, and customization.
当你需要完成以下需求时,可使用本技能:
  • 构建基于文档的应用程序,在标签页中管理多个文档(类似Visual Studio、Visual Studio Code或现代网页浏览器)
  • 实现浏览器式标签界面,集成窗口边框与标签导航功能
  • 创建多文档界面(MDI),采用现代标签布局替代传统MDI窗口
  • 启用拖离功能,允许用户将标签拖出以创建浮动窗口
  • 支持跨窗口标签合并,通过拖拽操作在多个窗口间移动标签
  • 实现动态标签管理,支持添加/关闭/选择标签及新建标签按钮
  • 构建兼容MVVM的标签界面,将标签与可观察集合进行数据绑定
  • 创建专业桌面应用程序,需要灵活的工作区组织方式
  • 实现代码编辑器、文档查看器或内容管理工具,采用标签式导航
  • 支持多窗口布局,标签可集成到窗口边框中或作为内容展示
本指南涵盖Tabbed Window控件的所有方面,包括设置、窗口模式、标签管理、数据绑定、可拖离窗口、标签合并和自定义配置。

Component Overview

组件概述

The Tabbed Window is a powerful combination of
SfChromelessWindow
and
SfTabControl
that enables professional document-based applications with:
  • Drag-and-Drop Reordering - Intuitive tab reordering within the tab bar or between windows
  • Tear-Off Windows - Create floating windows by dragging tabs outside window boundaries
  • Tab Merging - Move tabs between multiple TabbedWindow instances with validation
  • Flexible Tab Management - Dynamic add, remove, and select operations with close/new tab buttons
  • MVVM Support - Full data binding through ItemsSource for data-driven scenarios
  • Window Type Modes - Tabbed mode (chrome-integrated) or Normal mode (content-based)
  • Content Customization - Templates for headers, icons, and content
  • Event-Driven Architecture - Comprehensive events for all tab operations
Key Assemblies Required:
  • Syncfusion.SfChromelessWindow.WPF
  • Syncfusion.Shared.WPF
Namespace:
xml
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
Tabbed Window
SfChromelessWindow
SfTabControl
的强大组合,可为专业文档类应用程序提供以下功能:
  • 拖拽重排 - 在标签栏内或跨窗口直观地重新排列标签
  • 可拖离窗口 - 将标签拖出窗口边界即可创建浮动窗口
  • 标签合并 - 在多个TabbedWindow实例间移动标签,并支持验证操作
  • 灵活的标签管理 - 动态添加、删除、选择标签,支持关闭/新建标签按钮
  • MVVM支持 - 通过ItemsSource实现完整的数据绑定,适用于数据驱动场景
  • 窗口类型模式 - 标签模式(集成窗口边框)或普通模式(基于内容)
  • 内容自定义 - 可为标签头、图标和内容设置模板
  • 事件驱动架构 - 为所有标签操作提供全面的事件支持
所需关键程序集:
  • Syncfusion.SfChromelessWindow.WPF
  • Syncfusion.Shared.WPF
命名空间:
xml
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"

Documentation and Navigation Guide

文档与导航指南

Getting Started

快速入门

📄 Read: references/getting-started.md
When you need to:
  • Install and reference required assemblies
  • Create your first tabbed window in XAML or code-behind
  • Understand Window Type Modes (Tabbed vs Normal)
  • Choose the right mode for your application
  • Create basic tab items
  • Configure essential properties
Key Topics: Installation, basic window setup,
WindowType
property, Tabbed vs Normal mode comparison, assembly references, namespace imports

📄 阅读: references/getting-started.md
当你需要完成以下操作时:
  • 安装并引用所需程序集
  • 在XAML或代码后置中创建首个标签窗口
  • 了解窗口类型模式(标签模式vs普通模式)
  • 为应用选择合适的模式
  • 创建基础标签项
  • 配置核心属性
核心主题: 安装、基础窗口设置、
WindowType
属性、标签模式与普通模式对比、程序集引用、命名空间导入

Tab Management

标签管理

📄 Read: references/tab-management.md
When you need to:
  • Add close buttons to tabs
  • Enable the new tab (+) button
  • Handle NewTabRequested event for dynamic tab creation
  • Customize the new tab button appearance
  • Implement keyboard shortcuts (Ctrl+Tab, Ctrl+Shift+Tab, Ctrl+T)
  • Support middle-click to close tabs
  • Programmatically add, remove, or select tabs
Key Topics:
CloseButtonVisibility
,
EnableNewTabButton
,
NewTabRequested
event,
NewTabButtonStyle
, keyboard shortcuts, tab selection

📄 阅读: references/tab-management.md
当你需要完成以下操作时:
  • 为标签添加关闭按钮
  • 启用新建标签(+)按钮
  • 处理NewTabRequested事件以动态创建标签
  • 自定义新建标签按钮的外观
  • 实现键盘快捷键(Ctrl+Tab、Ctrl+Shift+Tab、Ctrl+T)
  • 支持中键点击关闭标签
  • 以编程方式添加、删除或选择标签
核心主题:
CloseButtonVisibility
EnableNewTabButton
NewTabRequested
事件、
NewTabButtonStyle
、键盘快捷键、标签选择

Data Binding (MVVM)

数据绑定(MVVM)

📄 Read: references/data-binding.md
When you need to:
  • Bind tabs to a ViewModel collection
  • Implement MVVM pattern with tabbed windows
  • Use
    ItemsSource
    for data-driven tab scenarios
  • Create tab models and ViewModels
  • Customize tab headers and content through templates
  • Configure
    ItemTemplate
    and
    ContentTemplate
  • Use
    ItemContainerStyle
    for tab styling
  • Handle dynamic collection updates with ObservableCollection
Key Topics: MVVM pattern,
ItemsSource
binding,
ItemTemplate
,
ContentTemplate
,
ItemContainerStyle
, ObservableCollection, tab models

📄 阅读: references/data-binding.md
当你需要完成以下操作时:
  • 将标签绑定到ViewModel集合
  • 结合标签窗口实现MVVM模式
  • 使用
    ItemsSource
    实现数据驱动的标签场景
  • 创建标签模型与ViewModel
  • 通过模板自定义标签头和内容
  • 配置
    ItemTemplate
    ContentTemplate
  • 使用
    ItemContainerStyle
    设置标签样式
  • 通过ObservableCollection处理动态集合更新
核心主题: MVVM模式、
ItemsSource
绑定、
ItemTemplate
ContentTemplate
ItemContainerStyle
、ObservableCollection、标签模型

Tab Merging and Floating Windows

标签合并与浮动窗口

📄 Read: references/merge-tabs.md
When you need to:
  • Enable tear-off functionality to create floating windows
  • Understand how tabs become independent windows
  • Reattach floating tabs back to main window
  • Merge tabs between multiple windows
  • Validate merge operations with
    PreviewTabMerge
    event
  • Control which tabs can be moved
  • Transform items during merge operations
  • Handle multi-window workspace scenarios
Key Topics: Tear-off windows, drag-outside behavior, floating window lifecycle,
PreviewTabMerge
event,
TabMergePreviewEventArgs
, cross-window merging, merge validation

📄 阅读: references/merge-tabs.md
当你需要完成以下操作时:
  • 启用拖离功能以创建浮动窗口
  • 了解标签如何转换为独立窗口
  • 将浮动标签重新附加到主窗口
  • 在多个窗口间合并标签
  • 通过
    PreviewTabMerge
    事件验证合并操作
  • 控制可移动的标签范围
  • 在合并操作中转换项
  • 处理多窗口工作区场景
核心主题: 可拖离窗口、拖出边界行为、浮动窗口生命周期、
PreviewTabMerge
事件、
TabMergePreviewEventArgs
、跨窗口合并、合并验证

Customization and Styling

自定义与样式设置

📄 Read: references/customization.md
When you need to:
  • Apply Syncfusion themes
  • Customize window chrome appearance
  • Style tab headers and content areas
  • Create custom header and content templates
  • Customize close button appearance
  • Configure drag-drop visual feedback
  • Set colors, fonts, and spacing
  • Implement responsive design
  • Follow best practices for professional appearance
Key Topics: Theme application, style customization, template customization, visual appearance,
AllowDragDrop
, responsive design, professional styling

📄 阅读: references/customization.md
当你需要完成以下操作时:
  • 应用Syncfusion主题
  • 自定义窗口边框外观
  • 设置标签头和内容区域的样式
  • 创建自定义的标签头和内容模板
  • 自定义关闭按钮的外观
  • 配置拖拽操作的视觉反馈
  • 设置颜色、字体和间距
  • 实现响应式设计
  • 遵循专业外观的最佳实践
核心主题: 主题应用、样式自定义、模板自定义、视觉外观、
AllowDragDrop
、响应式设计、专业样式设置

Quick Start Example

快速入门示例

Basic Tabbed Window with Close Buttons

带关闭按钮的基础标签窗口

XAML:
xml
<Window x:Class="TabbedWindowApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
    
    <syncfusion:SfChromelessWindow 
        Title="Document Manager"
        WindowType="Tabbed"
        Height="600" 
        Width="900">
        
        <syncfusion:SfTabControl 
            AllowDragDrop="True"
            EnableNewTabButton="True"
            NewTabRequested="OnNewTabRequested">
            
            <syncfusion:SfTabItem 
                Header="Document 1" 
                CloseButtonVisibility="Visible">
                <TextBlock Text="Welcome to Document 1" 
                          Margin="20"/>
            </syncfusion:SfTabItem>
            
            <syncfusion:SfTabItem 
                Header="Document 2" 
                CloseButtonVisibility="Visible">
                <TextBlock Text="Welcome to Document 2" 
                          Margin="20"/>
            </syncfusion:SfTabItem>
            
        </syncfusion:SfTabControl>
        
    </syncfusion:SfChromelessWindow>
    
</Window>
Code-Behind:
csharp
using Syncfusion.Windows.Controls;

public partial class MainWindow : SfChromelessWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void OnNewTabRequested(object sender, NewTabRequestedEventArgs e)
    {
        var tabCount = ((SfTabControl)sender).Items.Count;
        var newTab = new SfTabItem 
        { 
            Header = $"Document {tabCount + 1}",
            Content = new TextBlock 
            { 
                Text = $"New Document {tabCount + 1}",
                Margin = new Thickness(20)
            },
            CloseButtonVisibility = Visibility.Visible
        };
        
        e.Item = newTab;
    }
}
XAML:
xml
<Window x:Class="TabbedWindowApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:syncfusion="http://schemas.syncfusion.com/wpf">
    
    <syncfusion:SfChromelessWindow 
        Title="Document Manager"
        WindowType="Tabbed"
        Height="600" 
        Width="900">
        
        <syncfusion:SfTabControl 
            AllowDragDrop="True"
            EnableNewTabButton="True"
            NewTabRequested="OnNewTabRequested">
            
            <syncfusion:SfTabItem 
                Header="Document 1" 
                CloseButtonVisibility="Visible">
                <TextBlock Text="Welcome to Document 1" 
                          Margin="20"/>
            </syncfusion:SfTabItem>
            
            <syncfusion:SfTabItem 
                Header="Document 2" 
                CloseButtonVisibility="Visible">
                <TextBlock Text="Welcome to Document 2" 
                          Margin="20"/>
            </syncfusion:SfTabItem>
            
        </syncfusion:SfTabControl>
        
    </syncfusion:SfChromelessWindow>
    
</Window>
代码后置:
csharp
using Syncfusion.Windows.Controls;

public partial class MainWindow : SfChromelessWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void OnNewTabRequested(object sender, NewTabRequestedEventArgs e)
    {
        var tabCount = ((SfTabControl)sender).Items.Count;
        var newTab = new SfTabItem 
        { 
            Header = $"Document {tabCount + 1}",
            Content = new TextBlock 
            { 
                Text = $"New Document {tabCount + 1}",
                Margin = new Thickness(20)
            },
            CloseButtonVisibility = Visibility.Visible
        };
        
        e.Item = newTab;
    }
}

Common Patterns

常见模式

Pattern 1: Document Editor with Drag-Drop and New Tab

模式1:带拖拽与新建标签的文档编辑器

xml
<syncfusion:SfChromelessWindow WindowType="Tabbed">
    <syncfusion:SfTabControl 
        AllowDragDrop="True"
        EnableNewTabButton="True"
        NewTabRequested="OnNewTabRequested">
        <!-- Tabs here -->
    </syncfusion:SfTabControl>
</syncfusion:SfChromelessWindow>
xml
<syncfusion:SfChromelessWindow WindowType="Tabbed">
    <syncfusion:SfTabControl 
        AllowDragDrop="True"
        EnableNewTabButton="True"
        NewTabRequested="OnNewTabRequested">
        <!-- Tabs here -->
    </syncfusion:SfTabControl>
</syncfusion:SfChromelessWindow>

Pattern 2: MVVM Data-Bound Tabs

模式2:MVVM数据绑定标签

xml
<syncfusion:SfTabControl ItemsSource="{Binding OpenDocuments}">
    <syncfusion:SfTabControl.ItemContainerStyle>
        <Style TargetType="syncfusion:SfTabItem">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock Text="{Binding Title}" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </syncfusion:SfTabControl.ItemContainerStyle>
    
    <syncfusion:SfTabControl.ContentTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Content}" />
        </DataTemplate>
    </syncfusion:SfTabControl.ContentTemplate>
</syncfusion:SfTabControl>
xml
<syncfusion:SfTabControl ItemsSource="{Binding OpenDocuments}">
    <syncfusion:SfTabControl.ItemContainerStyle>
        <Style TargetType="syncfusion:SfTabItem">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock Text="{Binding Title}" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </syncfusion:SfTabControl.ItemContainerStyle>
    
    <syncfusion:SfTabControl.ContentTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Content}" />
        </DataTemplate>
    </syncfusion:SfTabControl.ContentTemplate>
</syncfusion:SfTabControl>

Pattern 3: Multi-Window with Merge Validation

模式3:带合并验证的多窗口

csharp
private void OnPreviewTabMerge(object sender, TabMergePreviewEventArgs e)
{
    var draggedItem = e.DraggedItem;
    
    // Validate merge operation
    if (draggedItem is DocumentTab doc && doc.IsReadOnly)
    {
        e.Allow = false;
        MessageBox.Show("Cannot move read-only documents");
        return;
    }
    
    e.Allow = true;
}
csharp
private void OnPreviewTabMerge(object sender, TabMergePreviewEventArgs e)
{
    var draggedItem = e.DraggedItem;
    
    // Validate merge operation
    if (draggedItem is DocumentTab doc && doc.IsReadOnly)
    {
        e.Allow = false;
        MessageBox.Show("Cannot move read-only documents");
        return;
    }
    
    e.Allow = true;
}

Key Properties and Events

核心属性与事件

Core Properties

核心属性

PropertyTypeDescription
WindowType
WindowType
Tabbed
(chrome-integrated) or
Normal
(content-based)
AllowDragDrop
boolEnable drag-drop reordering and tear-off
EnableNewTabButton
boolShow/hide the new tab (+) button
SelectedItem
objectCurrently active tab
SelectedIndex
intIndex of active tab
ItemsSource
IEnumerableBind tabs to a collection (MVVM)
CloseButtonVisibility
VisibilityShow/hide close button per tab
属性类型描述
WindowType
WindowType
Tabbed
(集成窗口边框)或
Normal
(基于内容)
AllowDragDrop
bool启用拖拽重排与拖离功能
EnableNewTabButton
bool显示/隐藏新建标签(+)按钮
SelectedItem
object当前激活的标签
SelectedIndex
int激活标签的索引
ItemsSource
IEnumerable将标签绑定到集合(MVVM场景)
CloseButtonVisibility
Visibility控制单个标签的关闭按钮显示/隐藏

Important Events

重要事件

EventDescription
NewTabRequested
Fired when user clicks the + button; set
e.Item
to create tab
PreviewTabMerge
Fired before tab moves between windows; set
e.Allow
to validate
SelectionChanged
Fired when active tab changes
事件描述
NewTabRequested
用户点击+按钮时触发;设置
e.Item
以创建新标签
PreviewTabMerge
标签跨窗口移动前触发;设置
e.Allow
以验证操作
SelectionChanged
激活标签变更时触发

Styling Properties

样式属性

PropertyDescription
NewTabButtonStyle
Style for the new tab button
ItemTemplate
DataTemplate for tab headers
ContentTemplate
DataTemplate for tab content
ItemContainerStyle
Style for SfTabItem containers
属性描述
NewTabButtonStyle
新建标签按钮的样式
ItemTemplate
标签头的数据模板
ContentTemplate
标签内容的数据模板
ItemContainerStyle
SfTabItem容器的样式

Common Use Cases

常见用例

Use Case 1: Code Editor or IDE

用例1:代码编辑器或IDE

Scenario: Building a development tool with multiple file tabs
Mode: Tabbed (chrome-integrated)
Features: Drag-drop reordering, close buttons, new tab button, tear-off for multi-monitor
场景: 构建带多文件标签的开发工具
模式: Tabbed(集成窗口边框)
功能: 拖拽重排、关闭按钮、新建标签按钮、多显示器拖离支持

Use Case 2: Document Management System

用例2:文档管理系统

Scenario: Enterprise application managing multiple documents
Mode: Tabbed or Normal
Features: MVVM binding, tab merging, dynamic add/remove, data-driven tabs
场景: 管理多文档的企业级应用程序
模式: Tabbed或Normal
功能: MVVM绑定、标签合并、动态添加/删除、数据驱动标签

Use Case 3: Multi-Window Workspace

用例3:多窗口工作区

Scenario: Professional tool with floating panels and documents
Mode: Tabbed
Features: Tear-off windows, cross-window merging, merge validation, flexible layouts
场景: 带浮动面板与文档的专业工具
模式: Tabbed
功能: 可拖离窗口、跨窗口合并、合并验证、灵活布局

Use Case 4: Browser-Style Application

用例4:浏览器式应用程序

Scenario: Web-like interface with browser tabs
Mode: Tabbed
Features: Close buttons, new tab button, drag reordering, keyboard shortcuts
场景: 类网页界面的浏览器式标签
模式: Tabbed
功能: 关闭按钮、新建标签按钮、拖拽重排、键盘快捷键

Best Practices

最佳实践

  1. Choose the Right Mode: Use Tabbed mode for document-centric apps, Normal mode when tabs are secondary navigation
  2. Enable Drag-Drop: Set
    AllowDragDrop="True"
    for intuitive reordering and tear-off functionality
  3. Handle NewTabRequested: Always implement this event handler when
    EnableNewTabButton="True"
  4. MVVM Pattern: Use
    ItemsSource
    binding for data-driven scenarios with clean separation of concerns
  5. Validate Merges: Use
    PreviewTabMerge
    to control which tabs can be moved between windows
  6. Keyboard Support: Document keyboard shortcuts for users (Ctrl+Tab, Ctrl+Shift+Tab, Ctrl+T)
  7. Visual Feedback: Ensure drag-drop operations have clear visual indicators for user guidance
  1. 选择合适模式: 文档中心类应用使用Tabbed模式,标签为次要导航时使用Normal模式
  2. 启用拖拽功能: 设置
    AllowDragDrop="True"
    以支持直观的重排与拖离功能
  3. 处理NewTabRequested事件: 当设置
    EnableNewTabButton="True"
    时,务必实现该事件处理程序
  4. 采用MVVM模式: 数据驱动场景使用
    ItemsSource
    绑定,实现关注点分离
  5. 验证合并操作: 使用
    PreviewTabMerge
    控制可跨窗口移动的标签范围
  6. 支持键盘快捷键: 为用户提供键盘快捷键文档(Ctrl+Tab、Ctrl+Shift+Tab、Ctrl+T)
  7. 提供视觉反馈: 确保拖拽操作有清晰的视觉提示,引导用户操作

Troubleshooting Quick Tips

故障排查快速提示

  • Tabs not draggable? Verify
    AllowDragDrop="True"
    is set
  • New tab button not appearing? Check
    EnableNewTabButton="True"
    and ensure event handler is attached
  • Tab merging not working? Ensure both windows have
    AllowDragDrop
    enabled
  • MVVM binding not working? Verify
    ItemTemplate
    and
    ContentTemplate
    are configured
  • Assembly reference errors? Ensure both
    Syncfusion.SfChromelessWindow.WPF
    and
    Syncfusion.Shared.WPF
    are referenced
  • 标签无法拖拽? 确认已设置
    AllowDragDrop="True"
  • 新建标签按钮不显示? 检查
    EnableNewTabButton="True"
    并确保已绑定事件处理程序
  • 标签合并不生效? 确保所有窗口都已启用
    AllowDragDrop
  • MVVM绑定不生效? 验证
    ItemTemplate
    ContentTemplate
    配置正确
  • 程序集引用错误? 确保已同时引用
    Syncfusion.SfChromelessWindow.WPF
    Syncfusion.Shared.WPF