deathlybower959
deathlybower959
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
(i have to set a default value because i initialize this class to get default values)
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
but its always null
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
i tried this
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
private readonly ThemeState _state;

public MyClass(ThemeState state = null)
{
_state = state;
}
private readonly ThemeState _state;

public MyClass(ThemeState state = null)
{
_state = state;
}
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
Im trying to access it in a .cs file, but im having some trouble
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
and i have added it to my services in MainWindow.xaml.cs
services.AddSingleton<ThemeState>();

Resources.Add("services", services.BuildServiceProvider());
services.AddSingleton<ThemeState>();

Resources.Add("services", services.BuildServiceProvider());
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
its a simple state
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
this is my ThemeState.cs
public class ThemeState
{
public CssBuilder ThemeCSS { get; set; }
public event Action OnChange;

public ThemeState() { ThemeCSS = CssBuilder.FromFile(ThemePath, ":root"); }

public static readonly string WWWRootPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "wwwroot");

public static readonly string ThemePath = Path.Combine(WWWRootPath, "css", "theme.css");

public void ApplyTheme(CssBuilder css)
{
ThemeCSS = css;
OnChange?.Invoke();
}

public void UpdateTheme(string property, string value)
{
ThemeCSS.SetProperty(property, value);
OnChange?.Invoke();
}
}
public class ThemeState
{
public CssBuilder ThemeCSS { get; set; }
public event Action OnChange;

public ThemeState() { ThemeCSS = CssBuilder.FromFile(ThemePath, ":root"); }

public static readonly string WWWRootPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "wwwroot");

public static readonly string ThemePath = Path.Combine(WWWRootPath, "css", "theme.css");

public void ApplyTheme(CssBuilder css)
{
ThemeCSS = css;
OnChange?.Invoke();
}

public void UpdateTheme(string property, string value)
{
ThemeCSS.SetProperty(property, value);
OnChange?.Invoke();
}
}
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
i think so yea
14 replies
CC#
Created by deathlybower959 on 11/20/2023 in #help
Blazor Services
(ping if replying)
14 replies