@@ -10,15 +10,13 @@ namespace BootstrapBlazor.Components;
1010/// <summary>
1111/// DockViewV2 组件
1212/// </summary>
13- public partial class DockViewV2
13+ public partial class DockViewV2 : IDisposable
1414{
1515 /// <summary>
1616 /// 获得/设置 DockView 名称 默认 null 用于本地存储识别
1717 /// </summary>
1818 [ Parameter ]
19- #if NET6_0_OR_GREATER
2019 [ EditorRequired ]
21- #endif
2220 [ NotNull ]
2321 public string ? Name { get ; set ; }
2422
@@ -139,15 +137,18 @@ public partial class DockViewV2
139137 [ NotNull ]
140138 private IConfiguration ? Configuration { get ; set ; }
141139
140+ [ Inject ]
141+ [ NotNull ]
142+ private IThemeProvider ? ThemeProviderService { get ; set ; }
143+
142144 private string ? ClassString => CssBuilder . Default ( "bb-dockview" )
143- . AddClass ( Theme . ToDescriptionString ( ) )
144145 . AddClassFromAttributes ( AdditionalAttributes )
145146 . Build ( ) ;
146147
147148 private readonly List < DockViewComponentBase > _components = [ ] ;
148149
149150 [ NotNull ]
150- private DockViewOptions ? _options = default ! ;
151+ private DockViewOptions ? _options = null ;
151152
152153 /// <summary>
153154 /// <inheritdoc/>
@@ -158,6 +159,8 @@ protected override void OnInitialized()
158159
159160 var section = Configuration . GetSection ( nameof ( DockViewOptions ) ) ;
160161 _options = section . Exists ( ) ? section . Get < DockViewOptions > ( ) : new ( ) ;
162+
163+ ThemeProviderService . ThemeChangedAsync += OnThemeChangedAsync ;
161164 }
162165
163166 /// <summary>
@@ -193,6 +196,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
193196 ShowMaximize = ShowMaximize ,
194197 Renderer = Renderer ,
195198 LayoutConfig = LayoutConfig ,
199+ Theme = Theme . ToDescriptionString ( ) ,
196200 InitializedCallback = nameof ( InitializedCallbackAsync ) ,
197201 PanelVisibleChangedCallback = nameof ( PanelVisibleChangedCallbackAsync ) ,
198202 LockChangedCallback = nameof ( LockChangedCallbackAsync ) ,
@@ -224,6 +228,12 @@ public async Task Reset(string? layoutConfig = null)
224228 /// <returns></returns>
225229 public Task < string ? > SaveLayout ( ) => InvokeAsync < string ? > ( "save" , Id ) ;
226230
231+ private Task OnThemeChangedAsync ( string themeName )
232+ {
233+ Theme = themeName == "dark" ? DockViewTheme . Dark : DockViewTheme . Light ;
234+ return Task . CompletedTask ;
235+ }
236+
227237 /// <summary>
228238 /// 标签页关闭回调方法 由 JavaScript 调用
229239 /// </summary>
@@ -271,4 +281,21 @@ public async Task SplitterCallbackAsync()
271281 await OnSplitterCallbackAsync ( ) ;
272282 }
273283 }
284+
285+ private void Dispose ( bool disposing )
286+ {
287+ if ( disposing )
288+ {
289+ ThemeProviderService . ThemeChangedAsync -= OnThemeChangedAsync ;
290+ }
291+ }
292+
293+ /// <summary>
294+ /// <inheritdoc/>
295+ /// </summary>
296+ public void Dispose ( )
297+ {
298+ Dispose ( true ) ;
299+ GC . SuppressFinalize ( this ) ;
300+ }
274301}
0 commit comments