Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bedd9c9

Browse files
committed
Add missing step for theme persistence.
1 parent 81c859b commit bedd9c9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

RadzenBlazorDemos/Pages/ThemeServicePage.razor

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,31 @@ builder.Services.AddRadzenCookieThemeService(options =>
3232
<code>
3333
@@inject CookieThemeService CookieThemeService
3434
</code>
35+
</pre>
36+
<RadzenText TextStyle="TextStyle.H6" TagName="TagName.H3" class="rz-mt-12 rz-mb-4">3. Open the <code>App.razor</code> file of your application and add this code<code>@@code{}</code>:</RadzenText>
37+
<pre class="rz-p-4">
38+
<code>
39+
@@code {
40+
[CascadingParameter]
41+
private HttpContext HttpContext { get; set; }
42+
43+
[Inject]
44+
private ThemeService ThemeService { get; set; }
45+
46+
protected override void OnInitialized()
47+
{
48+
base.OnInitialized();
49+
50+
if (HttpContext != null)
51+
{
52+
var theme = HttpContext.Request.Cookies["MyApplicationTheme"];
53+
54+
if (!string.IsNullOrEmpty(theme))
55+
{
56+
ThemeService.SetTheme(theme, false);
57+
}
58+
}
59+
}
60+
}
61+
</code>
3562
</pre>

0 commit comments

Comments
 (0)