Skip to content

Fix: Apply CachedTabControl to MainWindow and fix dark theme inheritance#308

Merged
donkeyProgramming merged 1 commit intodonkeyProgramming:masterfrom
Szy-Cathay:fix/apply-cached-tab-control
Mar 22, 2026
Merged

Fix: Apply CachedTabControl to MainWindow and fix dark theme inheritance#308
donkeyProgramming merged 1 commit intodonkeyProgramming:masterfrom
Szy-Cathay:fix/apply-cached-tab-control

Conversation

@Szy-Cathay
Copy link
Contributor

Applies the newly created CachedTabControl to the MainWindow, replacing the native TabControl. This completes the implementation of visual tree caching for editor tabs, ensuring that UI states (such as scroll position and active selections) are preserved when switching between documents, while fully retaining the application's native drag-and-drop events and context menus.

Technical Rationale (Why this approach?):

  • Why an explicit ControlTemplate override? When subclassing WPF controls like TabControl, the framework often drops the implicit styles applied to the base class, which can lead to a completely blank UI or rendering crashes. By explicitly defining the ControlTemplate and strictly setting TargetType="{x:Type views:CachedTabControl}", we force the WPF rendering engine to correctly construct the visual tree for our custom caching container (PART_ItemsHolder).
  • Why bind to TabItem.Static.Background? WPF's default UI virtualization destroys and recreates visual elements on tab switch. Since our CachedTabControl overrides this by keeping all elements in memory and merely toggling Visibility.Collapsed, relying on default system brushes can cause severe theme tearing or blinding white backgrounds when tabs lose focus. By explicitly routing the Background and BorderBrush properties to {DynamicResource TabItem.Static.Background} and {DynamicResource App.Border}, we guarantee that our cached container strictly inherits AssetEditor's custom Dark Theme dictionaries, completely bypassing WPF's native theme disconnects.

Applies the newly created `CachedTabControl` to the `MainWindow`, replacing the native `TabControl`. This completes the implementation of visual tree caching for editor tabs, ensuring that UI states (such as scroll position and active selections) are preserved when switching between documents, while fully retaining the application's native drag-and-drop events and context menus.

**Technical Rationale (Why this approach?):**
* **Why an explicit `ControlTemplate` override?** When subclassing WPF controls like `TabControl`, the framework often drops the implicit styles applied to the base class, which can lead to a completely blank UI or rendering crashes. By explicitly defining the `ControlTemplate` and strictly setting `TargetType="{x:Type views:CachedTabControl}"`, we force the WPF rendering engine to correctly construct the visual tree for our custom caching container (`PART_ItemsHolder`).
* **Why bind to `TabItem.Static.Background`?** WPF's default UI virtualization destroys and recreates visual elements on tab switch. Since our `CachedTabControl` overrides this by keeping all elements in memory and merely toggling `Visibility.Collapsed`, relying on default system brushes can cause severe theme tearing or blinding white backgrounds when tabs lose focus. By explicitly routing the `Background` and `BorderBrush` properties to `{DynamicResource TabItem.Static.Background}` and `{DynamicResource App.Border}`, we guarantee that our cached container strictly inherits AssetEditor's custom Dark Theme dictionaries, completely bypassing WPF's native theme disconnects.
@donkeyProgramming donkeyProgramming merged commit 35e724f into donkeyProgramming:master Mar 22, 2026
1 check passed
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