@@ -137,6 +137,9 @@ public VisualTreeControl(IComponentHub componentHub, IPageContext pageContext)
137137 // convention documented in the Theme model).
138138 // 3. Otherwise leave Theme null - downstream IconTheme falls back
139139 // to TypeIconTheme.Default.
140+ // Per-user theme overrides are wired by application code: the
141+ // page's Process override calls UseTheme<T>() based on whatever
142+ // store the application maintains (session, identity profile, …).
140143 var applicationContext = pageContext ? . ApplicationContext ;
141144 Theme = applicationContext ? . DefaultTheme
142145 ?? componentHub ? . ThemeManager ? . Themes
@@ -189,19 +192,37 @@ public VisualTreeControl(IComponentHub componentHub, IPageContext pageContext)
189192 /// </summary>
190193 /// <typeparam name="TTheme">The theme type to use.</typeparam>
191194 /// <returns>The current instance for method chaining.</returns>
192- public virtual VisualTreeControl UseTheme < TTheme > ( ) where TTheme : class , ITheme
195+ public virtual VisualTreeControl UseTheme < TTheme > ( )
196+ where TTheme : class , ITheme
193197 {
194198 var resolved = _componentHub ? . ThemeManager ?
195199 . GetThemes ( _pageContext ? . ApplicationContext , typeof ( TTheme ) )
196200 ? . FirstOrDefault ( ) ;
197- if ( resolved is null )
201+
202+ return UseTheme ( resolved ) ;
203+ }
204+
205+ /// <summary>
206+ /// Overrides the active theme with the supplied resolved theme
207+ /// context. The call is a no-op when <paramref name="theme"/> is
208+ /// <see langword="null"/>; otherwise the previous theme is replaced
209+ /// and <see cref="OnThemeChanged"/> is invoked so subclasses can
210+ /// re-apply theme-specific resources. Use this overload when the
211+ /// theme has been resolved through a non-type lookup (cookie,
212+ /// session, identity preference, …).
213+ /// </summary>
214+ /// <param name="theme">The theme to activate.</param>
215+ /// <returns>The current instance for method chaining.</returns>
216+ public virtual VisualTreeControl UseTheme ( IThemeContext theme )
217+ {
218+ if ( theme is null || theme == Theme )
198219 {
199220 return this ;
200221 }
201222
202223 var previous = Theme ;
203- Theme = resolved ;
204- OnThemeChanged ( previous , resolved ) ;
224+ Theme = theme ;
225+ OnThemeChanged ( previous , theme ) ;
205226 return this ;
206227 }
207228
0 commit comments