@@ -31,18 +31,27 @@ public partial class PlanViewerControl : UserControl
3131 private Border ? _selectedNodeBorder ;
3232 private Brush ? _selectedNodeOriginalBorder ;
3333 private Thickness _selectedNodeOriginalThickness ;
34+ private PlanNode ? _selectedNode ;
3435
35- // Brushes
36+ // Brushes — accent/neutral tones that suit every theme
3637 private static readonly SolidColorBrush SelectionBrush = new ( Color . FromRgb ( 0x4F , 0xA3 , 0xFF ) ) ;
37- private static readonly SolidColorBrush TooltipBgBrush = new ( Color . FromRgb ( 0x1A , 0x1D , 0x23 ) ) ;
38- private static readonly SolidColorBrush TooltipBorderBrush = new ( Color . FromRgb ( 0x3A , 0x3D , 0x45 ) ) ;
39- private static readonly SolidColorBrush TooltipFgBrush = new ( Color . FromRgb ( 0xE4 , 0xE6 , 0xEB ) ) ;
40- private static readonly SolidColorBrush MutedBrush = new ( Color . FromRgb ( 0xE4 , 0xE6 , 0xEB ) ) ;
4138 private static readonly SolidColorBrush EdgeBrush = new ( Color . FromRgb ( 0x6B , 0x72 , 0x80 ) ) ;
42- private static readonly SolidColorBrush SectionHeaderBrush = new ( Color . FromRgb ( 0x4F , 0xA3 , 0xFF ) ) ;
43- private static readonly SolidColorBrush PropSeparatorBrush = new ( Color . FromRgb ( 0x2A , 0x2D , 0x35 ) ) ;
4439 private static readonly SolidColorBrush OrangeBrush = new ( Color . FromRgb ( 0xFF , 0xB3 , 0x47 ) ) ;
4540
41+ // Theme-aware brushes resolved at call time from Application.Resources
42+ private SolidColorBrush TooltipBgBrush =>
43+ ( TryFindResource ( "PlanTooltipBgBrush" ) as SolidColorBrush ) ?? new SolidColorBrush ( Color . FromRgb ( 0x1A , 0x1D , 0x23 ) ) ;
44+ private SolidColorBrush TooltipBorderBrush =>
45+ ( TryFindResource ( "PlanTooltipBorderBrush" ) as SolidColorBrush ) ?? new SolidColorBrush ( Color . FromRgb ( 0x3A , 0x3D , 0x45 ) ) ;
46+ private SolidColorBrush TooltipFgBrush =>
47+ ( TryFindResource ( "PlanPanelTextBrush" ) as SolidColorBrush ) ?? new SolidColorBrush ( Color . FromRgb ( 0xE4 , 0xE6 , 0xEB ) ) ;
48+ private SolidColorBrush MutedBrush =>
49+ ( TryFindResource ( "PlanPanelMutedBrush" ) as SolidColorBrush ) ?? new SolidColorBrush ( Color . FromRgb ( 0xE4 , 0xE6 , 0xEB ) ) ;
50+ private SolidColorBrush SectionHeaderBrush =>
51+ ( TryFindResource ( "PlanSectionHeaderBrush" ) as SolidColorBrush ) ?? new SolidColorBrush ( Color . FromRgb ( 0x4F , 0xA3 , 0xFF ) ) ;
52+ private SolidColorBrush PropSeparatorBrush =>
53+ ( TryFindResource ( "PlanPropSeparatorBrush" ) as SolidColorBrush ) ?? new SolidColorBrush ( Color . FromRgb ( 0x2A , 0x2D , 0x35 ) ) ;
54+
4655 // Current property section for collapsible groups
4756 private StackPanel ? _currentPropertySection ;
4857
@@ -55,6 +64,28 @@ public partial class PlanViewerControl : UserControl
5564 public PlanViewerControl ( )
5665 {
5766 InitializeComponent ( ) ;
67+ Helpers . ThemeManager . ThemeChanged += OnThemeChanged ;
68+ Unloaded += ( _ , _ ) => Helpers . ThemeManager . ThemeChanged -= OnThemeChanged ;
69+ }
70+
71+ private void OnThemeChanged ( string _ )
72+ {
73+ if ( _currentStatement == null ) return ;
74+
75+ var nodeToRestore = _selectedNode ;
76+ RenderStatement ( _currentStatement ) ;
77+
78+ if ( nodeToRestore == null ) return ;
79+
80+ // Find the re-created border for the previously selected node and reopen properties
81+ foreach ( var child in PlanCanvas . Children )
82+ {
83+ if ( child is Border b && b . Tag == nodeToRestore )
84+ {
85+ SelectNode ( b , nodeToRestore ) ;
86+ break ;
87+ }
88+ }
5889 }
5990
6091 public void LoadPlan ( string planXml , string label , string ? queryText = null )
@@ -488,14 +519,14 @@ void AddRow(string label, string value)
488519 var lbl = new TextBlock
489520 {
490521 Text = label ,
491- Foreground = new SolidColorBrush ( Color . FromRgb ( 0xE0 , 0xE0 , 0xE0 ) ) ,
522+ Foreground = MutedBrush ,
492523 FontSize = 12 ,
493524 Margin = new Thickness ( 0 , 1 , 12 , 1 )
494525 } ;
495526 var val = new TextBlock
496527 {
497528 Text = value ,
498- Foreground = new SolidColorBrush ( Colors . White ) ,
529+ Foreground = TooltipFgBrush ,
499530 FontSize = 12 ,
500531 FontWeight = FontWeights . SemiBold ,
501532 HorizontalAlignment = HorizontalAlignment . Right ,
@@ -528,8 +559,8 @@ void AddRow(string label, string value)
528559
529560 return new Border
530561 {
531- Background = new SolidColorBrush ( Color . FromRgb ( 0x1E , 0x1E , 0x2E ) ) ,
532- BorderBrush = new SolidColorBrush ( Color . FromRgb ( 0x3A , 0x3A , 0x5A ) ) ,
562+ Background = TooltipBgBrush ,
563+ BorderBrush = TooltipBorderBrush ,
533564 BorderThickness = new Thickness ( 1 ) ,
534565 Padding = new Thickness ( 10 , 6 , 10 , 6 ) ,
535566 CornerRadius = new CornerRadius ( 4 ) ,
@@ -571,6 +602,7 @@ private void SelectNode(Border border, PlanNode node)
571602 _selectedNodeOriginalBorder = border . BorderBrush ;
572603 _selectedNodeOriginalThickness = border . BorderThickness ;
573604 _selectedNodeBorder = border ;
605+ _selectedNode = node ;
574606 border . BorderBrush = SelectionBrush ;
575607 border . BorderThickness = new Thickness ( 2 ) ;
576608
@@ -1504,7 +1536,7 @@ private void AddPropertySection(string title)
15041536 Margin = new Thickness ( 0 , 2 , 0 , 0 ) ,
15051537 Padding = new Thickness ( 0 ) ,
15061538 Foreground = SectionHeaderBrush ,
1507- Background = new SolidColorBrush ( Color . FromArgb ( 0x18 , 0x4F , 0xA3 , 0xFF ) ) ,
1539+ Background = ( TryFindResource ( "BackgroundLighterBrush" ) as SolidColorBrush ) ?? new SolidColorBrush ( Color . FromArgb ( 0x18 , 0x4F , 0xA3 , 0xFF ) ) ,
15081540 BorderBrush = PropSeparatorBrush ,
15091541 BorderThickness = new Thickness ( 0 , 0 , 0 , 1 )
15101542 } ;
@@ -1568,6 +1600,7 @@ private void ClosePropertiesPanel()
15681600 _selectedNodeBorder . BorderThickness = _selectedNodeOriginalThickness ;
15691601 _selectedNodeBorder = null ;
15701602 }
1603+ _selectedNode = null ;
15711604 }
15721605
15731606 #endregion
@@ -1780,7 +1813,7 @@ private ToolTip BuildNodeTooltip(PlanNode node, List<PlanWarning>? allWarnings =
17801813 return tip ;
17811814 }
17821815
1783- private static void AddTooltipSection ( StackPanel parent , string title )
1816+ private void AddTooltipSection ( StackPanel parent , string title )
17841817 {
17851818 parent . Children . Add ( new TextBlock
17861819 {
@@ -1792,7 +1825,7 @@ private static void AddTooltipSection(StackPanel parent, string title)
17921825 } ) ;
17931826 }
17941827
1795- private static void AddTooltipRow ( StackPanel parent , string label , string value , bool isCode = false )
1828+ private void AddTooltipRow ( StackPanel parent , string label , string value , bool isCode = false )
17961829 {
17971830 var row = new StackPanel { Orientation = Orientation . Horizontal , Margin = new Thickness ( 0 , 1 , 0 , 1 ) } ;
17981831 row . Children . Add ( new TextBlock
@@ -1835,19 +1868,19 @@ private void ShowMissingIndexes(List<MissingIndex> indexes)
18351868 {
18361869 Text = mi . Table ,
18371870 FontWeight = FontWeights . SemiBold ,
1838- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#E4E6EB" ) ) ,
1871+ Foreground = TooltipFgBrush ,
18391872 FontSize = 12
18401873 } ) ;
18411874 headerRow . Children . Add ( new TextBlock
18421875 {
18431876 Text = $ " \u2014 Impact: ",
1844- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#E4E6EB" ) ) ,
1877+ Foreground = MutedBrush ,
18451878 FontSize = 12
18461879 } ) ;
18471880 headerRow . Children . Add ( new TextBlock
18481881 {
18491882 Text = $ "{ mi . Impact : F1} %",
1850- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#FFB347" ) ) ,
1883+ Foreground = OrangeBrush ,
18511884 FontSize = 12
18521885 } ) ;
18531886 itemPanel . Children . Add ( headerRow ) ;
@@ -1859,7 +1892,7 @@ private void ShowMissingIndexes(List<MissingIndex> indexes)
18591892 Text = mi . CreateStatement ,
18601893 FontFamily = new FontFamily ( "Consolas" ) ,
18611894 FontSize = 11 ,
1862- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#E4E6EB" ) ) ,
1895+ Foreground = TooltipFgBrush ,
18631896 Background = Brushes . Transparent ,
18641897 BorderThickness = new Thickness ( 0 ) ,
18651898 IsReadOnly = true ,
@@ -1932,7 +1965,7 @@ private void ShowWaitStats(List<WaitStatInfo> waits, bool isActualPlan)
19321965 {
19331966 Text = w . WaitType ,
19341967 FontSize = 12 ,
1935- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#E4E6EB" ) ) ,
1968+ Foreground = TooltipFgBrush ,
19361969 VerticalAlignment = VerticalAlignment . Center ,
19371970 Margin = new Thickness ( 0 , 2 , 10 , 2 )
19381971 } ;
@@ -1958,7 +1991,7 @@ private void ShowWaitStats(List<WaitStatInfo> waits, bool isActualPlan)
19581991 {
19591992 Text = $ "{ w . WaitTimeMs : N0} ms ({ w . WaitCount : N0} waits)",
19601993 FontSize = 12 ,
1961- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( "#E4E6EB" ) ) ,
1994+ Foreground = TooltipFgBrush ,
19621995 VerticalAlignment = VerticalAlignment . Center ,
19631996 Margin = new Thickness ( 0 , 2 , 0 , 2 )
19641997 } ;
@@ -2014,8 +2047,8 @@ private void ShowRuntimeSummary(PlanStatement statement)
20142047 {
20152048 RuntimeSummaryContent . Children . Clear ( ) ;
20162049
2017- var labelColor = "#E4E6EB" ;
2018- var valueColor = "#E4E6EB" ;
2050+ var labelBrush = MutedBrush ;
2051+ var valueBrush = TooltipFgBrush ;
20192052
20202053 var grid = new Grid ( ) ;
20212054 grid . ColumnDefinitions . Add ( new ColumnDefinition { Width = GridLength . Auto } ) ;
@@ -2030,7 +2063,7 @@ void AddRow(string label, string value)
20302063 {
20312064 Text = label ,
20322065 FontSize = 11 ,
2033- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( labelColor ) ) ,
2066+ Foreground = labelBrush ,
20342067 HorizontalAlignment = HorizontalAlignment . Left ,
20352068 Margin = new Thickness ( 0 , 1 , 8 , 1 )
20362069 } ;
@@ -2042,7 +2075,7 @@ void AddRow(string label, string value)
20422075 {
20432076 Text = value ,
20442077 FontSize = 11 ,
2045- Foreground = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( valueColor ) ) ,
2078+ Foreground = valueBrush ,
20462079 Margin = new Thickness ( 0 , 1 , 0 , 1 )
20472080 } ;
20482081 Grid . SetRow ( valueText , rowIndex ) ;
0 commit comments