Closed Gami13 closed 1 day ago
The base MaterialColorService
has an _appResources
field. Override the Initialize
method to get it (or Application.Current.Resources
should also work):
public class CustomMaterialColorService : MaterialColorService<CorePalette, Scheme<uint>, Scheme<Color>, LightSchemeMapper, DarkSchemeMapper>
{
private ResourceDictionary _appResources = null!;
// ...
public override void Initialize(ResourceDictionary resourceDictionary)
{
_appResources = resourceDictionary;
base.Initialize(resourceDictionary);
}
}
I also forgot to add that you have to call Initialize
in App.xaml.cs
before creating any pages:
+using MaterialColorUtilities.Maui;
public class App : Application
{
public App(CustomMaterialColorService colorService)
{
+ colorService.Initialize(this.Resources);
MainPage = // ...
}
}
This worked! Thank you so much for your help!
In fact it worked so well that it fixed mdc-maui's bug with cards always using light mode, amazing
The author described it in https://github.com/mdc-maui/mdc-maui/issues/36#issuecomment-1811473881 but never said what
_appResources
is, does't seem to work when initializing it toApplication.Current.Resources