Fix: Apply CachedTabControl to MainWindow and fix dark theme inheritance#308
Merged
donkeyProgramming merged 1 commit intodonkeyProgramming:masterfrom Mar 22, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applies the newly created
CachedTabControlto theMainWindow, replacing the nativeTabControl. 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?):
ControlTemplateoverride? When subclassing WPF controls likeTabControl, 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 theControlTemplateand strictly settingTargetType="{x:Type views:CachedTabControl}", we force the WPF rendering engine to correctly construct the visual tree for our custom caching container (PART_ItemsHolder).TabItem.Static.Background? WPF's default UI virtualization destroys and recreates visual elements on tab switch. Since ourCachedTabControloverrides this by keeping all elements in memory and merely togglingVisibility.Collapsed, relying on default system brushes can cause severe theme tearing or blinding white backgrounds when tabs lose focus. By explicitly routing theBackgroundandBorderBrushproperties 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.