From 27bea6e4b99e72999329b6994eec5969ad3aa61e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=83=AD=E5=BF=83=E5=B8=82=E6=B0=91=E7=9F=B3=E5=85=88?= =?UTF-8?q?=E7=94=9F?= <1249467256@qq.com> Date: Sun, 22 Mar 2026 00:03:15 +0800 Subject: [PATCH] Fix: Apply CachedTabControl to MainWindow and fix dark theme inheritance 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. --- AssetEditor/Views/MainWindow.xaml | 92 +++++++++++++++++-------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/AssetEditor/Views/MainWindow.xaml b/AssetEditor/Views/MainWindow.xaml index 2f657c76..58cc7cb3 100644 --- a/AssetEditor/Views/MainWindow.xaml +++ b/AssetEditor/Views/MainWindow.xaml @@ -158,28 +158,54 @@ - + x:Name="EditorsTabControl" BorderThickness="1, 1, 0, 0" > - - - + + + + + + + + - - - + + - + + + + + + + + + + + + + + + + + + @@ -193,22 +219,12 @@ - + - - - - + + + + @@ -224,18 +240,12 @@ - - - + +