Skip to content

Conversation

@NotYoojun
Copy link
Member

@NotYoojun NotYoojun commented Nov 18, 2025

This pull request refactors TabControl and TabItem's closing button logic.

  1. Reconsidered tab closing logic. Reverted implermentation introduced in Support cancellation for closing TabControl #342. All tab closing logic is now fully handled by user, by subscribing to ui:TabItemHelper.CloseRequested or ui:TabControlHelper.TabCloseRequested event and manually removing the Tab or its corresponding data item from the item source.
  2. Reconsidered closing button visibility. Previously it is determined by TabControl's IsAddTabButtonVisible property, now it is determined by its own attached property ui:TabItemHelper.IsClosable.

These changes ensures maximum flexibility and clear architecture, and is consistent with Windows UI behaviors.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the TabControl close button logic and event handling system. The main change is moving from a custom event handler pattern to WPF's standard routed event system, while also introducing a dedicated IsClosable property to control close button visibility per tab instead of relying on the TabControl's IsAddTabButtonVisible property.

  • Replaces typed event handlers with routed events for TabControl and TabItem close requests
  • Introduces TabItemHelper.IsClosable attached property to control individual tab close button visibility
  • Removes the TabItemExtension helper class and migrates to standard routed event subscription
  • Deletes the TabControlTest sample project in favor of improved examples in the Gallery

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
source/iNKORE.UI.WPF.Modern/Themes/Controls/TabControl.xaml Updates XAML triggers to use IsClosable property instead of IsAddTabButtonVisible for close button visibility
source/iNKORE.UI.WPF.Modern/Controls/TabItemExtension.cs Removed - no longer needed with routed event approach
source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabItemHelper.cs Adds IsClosable property, CloseRequested routed event, and refactored close button command handling
source/iNKORE.UI.WPF.Modern/Controls/Helpers/TabControlHelper.cs Converts TabCloseRequested and AddTabButtonClick to routed events, updates TabViewTabCloseRequestedEventArgs to inherit from RoutedEventArgs
source/iNKORE.UI.WPF.Modern.Gallery/Pages/Controls/Windows/TabViewPage.xaml.cs Updates example code to use new routed event subscription pattern with proper tab removal logic
source/iNKORE.UI.WPF.Modern.Gallery/Pages/Controls/Windows/TabViewPage.xaml Adds new example tab demonstrating IsClosable property usage and updates documentation text
samples/WpfApp1/WpfApp1.csproj Fixes project reference path casing from Inkore.UI.WPF.Modern.Controls to iNKORE.UI.WPF.Modern.Controls
samples/WpfApp1/MainWindow.xaml Contains unrelated UI changes (ScrollViewerEx to Expander)
samples/TabControlTest/* Entire sample project removed
iNKORE.UI.WPF.Modern.sln Removes TabControlTest project references from solution

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

NotYoojun and others added 3 commits November 18, 2025 16:53
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@NotYoojun
Copy link
Member Author

@copilot Help me draft a migration guide for this.

Copy link
Contributor

Copilot AI commented Nov 18, 2025

@NotYoojun I've opened a new pull request, #401, to work on those changes. Once the pull request is ready, I'll request review from you.

@NotYoojun NotYoojun merged commit 5e9beba into main Nov 18, 2025
2 checks passed
@NotYoojun
Copy link
Member Author

Migration Guide: TabControl & TabItem Closing Updates

If you're using TabControl alongside with closing handlings, please read this to upgrade your code base.

1. Close buttons

Before this update, the visibility of close buttons are controlled by the ui:TabControlHelper.IsAddTabButtonVisible property of the owner of that item. After this update, the visibility is controlled by a dedicated ui:TabItemHelper.IsClosable property of each TabItem.

The visibility by default is always true. So if you previously set ui:TabControl.IsAddTabButtonVisible to false in order to hide close buttons, you now need to update your code by setting ui:TabItem.IsClosable to false for each TabItem.

- <TabControl ui:TabControlHelper.IsAddTabButtonVisible="False">
+ <TabControl>
-     <TabItem Header="Tab 1" />
+     <TabItem Header="Tab 1" ui:TabItemHelper.IsClosable="False" />
-     <TabItem Header="Tab 2" />
+     <TabItem Header="Tab 2" ui:TabItemHelper.IsClosable="False" />
</TabControl>

If your items are generated dynamically or mapped from a data source, you can create a style to set the ui:TabItemHelper.IsClosable property for all TabItems. (don't ask me how to add styles in your project, that's basic WPF knowledge.)

2. Closing events

Previously, the tab closing is handled internally by TabControl and TabControlHelper. The internal closing logic is simply removing the TabItem from the TabControl.Items collection, which may not be suitable for all scenarios. From this update, you will be given full control of the closing logic by handling either ui:TabControlHelper.TabClosingRequested or ui:TabItemHelper.ClosingRequested event, and removing or not removing the TabItem based on your own logic.

The example code can be found in the Gallery app, by navigating to the "TabView" page and then the "Tab with closing handler" section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants