【发布时间】:2018-11-09 21:36:55
【问题描述】:
我有一个适用于 Android 和 IOS 的带有 MvvmCross 的 Xamarin Forms 应用程序,我想添加一个深色主题。我的想法是必须使用包含深色或浅色主题的资源的字典,并在启动时加载我需要的那个。
我在 MvxApplication 中注册了依赖项后添加了这个:
if (Mvx.IoCProvider.Resolve<ISettingsManager>().Theme == AppTheme.Dark)
{
Application.Current.Resources.Add(new ColorsDark());
}
else
{
Application.Current.Resources.Add(new ColorsLight());
}
ColorsDark 和 ColorsLight 是我的资源字典。之后我可以在Application.Current.Resources.MergedDictionaries 下看到新字典,但控件无法找到看起来的资源。但是,当我将它添加到 App.xaml 时它确实有效
<ResourceDictionary Source="Style/ColorsDark.xaml" />
我是否必须在代码中添加另一部分,或者这是一种错误的方法?
【问题讨论】:
标签: xamarin.forms