refactor: (core/TabControl) tab close button and close handling - #400
Conversation
There was a problem hiding this comment.
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.IsClosableattached property to control individual tab close button visibility - Removes the
TabItemExtensionhelper 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.
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>
|
@copilot Help me draft a migration guide for this. |
|
@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. |
Migration Guide: TabControl & TabItem Closing UpdatesIf you're using TabControl alongside with closing handlings, please read this to upgrade your code base. 1. Close buttonsBefore this update, the visibility of close buttons are controlled by the The visibility by default is always true. So if you previously set - <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 2. Closing eventsPreviously, the tab closing is handled internally by The example code can be found in the Gallery app, by navigating to the "TabView" page and then the "Tab with closing handler" section. |
This pull request refactors TabControl and TabItem's closing button logic.
ui:TabItemHelper.CloseRequestedorui:TabControlHelper.TabCloseRequestedevent and manually removing the Tab or its corresponding data item from the item source.ui:TabItemHelper.IsClosable.These changes ensures maximum flexibility and clear architecture, and is consistent with Windows UI behaviors.