I am creating a .net MAUI Blazor Hybrid app. In this, I want to create a dark and light theme using css stylesheets (no MudBlazor).
What I am trying now, is using a lightMode.css
and darkMode.css
that contain the correct colors for that theme. When dark mode is on, the MainLayout, and thus all pages, should use the darkMode.css
Example in MainLayout.razor
:
<HeadContent>
@if (isDark)
{
<link href="css/darkMode.css" rel="stylesheet"/>
}
else
{
<link href="css/lightMode.css" rel="stylesheet"/>
}
</HeadContent>
// HTML and c# here
However, this is not working. Looking at the page, none of this headcontent is in the tag of the page, and adding them directly to the index.html
page only results in the last of the files being applied.
I have looked at other solutions here, but they never mention how they achieved this with css, like in this post: Light and dark theme for my Maui Blazor app
Any suggestions as to how I can achieve a dark/light theme implementation with css? Other ideas are welcome too, but this looks like the most simple one to me.
Thanks in advance.