目前我只在 Android 模拟器上进行测试。我已经安装了 Theme Nuget 包。
在我的 App 构造函数中,我有:
// Load the desired theme (default to Light)
if (Current.Properties.TryGetValue("Theme", out object theme))
Resources = theme as ResourceDictionary;
else
Resources = new LightThemeResources();
然后我在 App 类中有一个方法:
public async Task SwitchTheme()
{
// Switch the current theme from List to Dark to Light
if (Resources?.GetType() == typeof(DarkThemeResources))
Resources = new LightThemeResources();
else
Resources = new DarkThemeResources();
// Persist the Theme
Current.Properties.Add("Theme", Resources);
await Current.SavePropertiesAsync();
}
当我调用该方法时,主题会从明暗等切换。但是当我重新启动应用程序时,它始终默认为 Light。好像“等待 Current.SavePropertiesAsync();” 不工作。
谁能提出问题可能是什么?