如何使用C#而不是XAML将两个ResourceDictionary对象合并到Application.Current.Resources中?
这是我的情况。本例中标记为Theme1和Theme2的两个资源字典如何使用C#而不是XAML将两个ResourceDictionary对象合并到Application.Current.Resources中?,c#,xamarin,xamarin.forms,resourcedictionary,mergeddictionaries,C#,Xamarin,Xamarin.forms,Resourcedictionary,Mergeddictionaries,这是我的情况。本例中标记为Theme1和Theme2的两个资源字典 public class Theme1 : ResourceDictionary { protected Theme1() { Add(nameof(IconColor), "#111111"); Add(nameof(PageBackgroundColor), "#111111"); } public Color IconC
public class Theme1 : ResourceDictionary
{
protected Theme1()
{
Add(nameof(IconColor), "#111111");
Add(nameof(PageBackgroundColor), "#111111");
}
public Color IconColor { get; }
public Color PageBackgroundColor { get;
}
public class Theme2 : ResourceDictionary
{
protected Theme2()
{
Add(nameof(IconColorA), "#222222");
Add(nameof(PageBackgroundColorA), "#222222");
}
public Color IconColorA { get; }
public Color PageBackgroundColorA { get; }
}
我想将这两项分配给Application.Current.Resources,但我只知道如何执行其中一项:
Application.Current.Resources = new Theme1();
或
如何将两者都分配给Application.Current.Resources?我认为在XAML中有一种方法可以做到这一点,但在C#中我找不到任何方法可以做到这一点。您可以将它们添加到
合并词典
属性:
Application.Current.Resources.MergedDictionaries.Add(new Theme1());
Application.Current.Resources.MergedDictionaries.Add(new Theme2());
Application.Current.Resources.MergedDictionaries.Add(new Theme1());
Application.Current.Resources.MergedDictionaries.Add(new Theme2());