From 5412b2d9976effbc2409392ea044b8f9b9033f9f Mon Sep 17 00:00:00 2001 From: meoacgx Date: Sat, 20 Dec 2025 19:21:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=AA=E8=A1=A8=E7=9B=98?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=B8=BB=E9=A2=98=E5=88=87=E6=8D=A2=E6=97=A0?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 ToggleDarkMode 方法中添加 StateHasChanged() 调用 - 在 OnInitializedAsync 方法中添加 StateHasChanged() 调用 - 确保在异步操作后 UI 能及时更新状态 - 解决 Blazor InteractiveServer 模式下的状态同步问题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/TelegramPanel.Web/Components/Layout/MainLayout.razor | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/TelegramPanel.Web/Components/Layout/MainLayout.razor b/src/TelegramPanel.Web/Components/Layout/MainLayout.razor index 7d7fcb5..cddda01 100644 --- a/src/TelegramPanel.Web/Components/Layout/MainLayout.razor +++ b/src/TelegramPanel.Web/Components/Layout/MainLayout.razor @@ -55,6 +55,8 @@ { // 从配置文件读取用户的主题偏好 _isDarkMode = await UiPreferences.GetIsDarkModeAsync(); + // 确保初始化后 UI 能正确显示主题 + StateHasChanged(); } private void ToggleDrawer() @@ -67,5 +69,7 @@ _isDarkMode = !_isDarkMode; // 保存主题偏好到配置文件 await UiPreferences.SetIsDarkModeAsync(_isDarkMode); + // 强制刷新组件状态,确保在异步操作后 UI 能及时更新 + StateHasChanged(); } }