我的代码像这样设置图标svg:
Current.Resources["HomePageIcon5"] = (new[] {
"resource://Japanese.Resources.5_Light.svg",
"resource://Japanese.Resources.5_Gray.svg",
"resource://Japanese.Resources.5_Dark.svg" })[thc];
对于更多的图标和相同的字符串也相同
"resource://Japanese.Resources."
出现多次。
有没有一种方法可以创建可以为我做到这一点的本地方法?我正在寻找的是我可以这样称呼的东西:
Current.Resources["HomePageIcon5"] = X("5_Light","5_Gray","5_Dark");
类似:
private static readonly _resourcesPath = "resource://Japanese.Resources.";
public void FillResource(string key, string value, int idx)
{
var content = new[]
{
_resourcesPath + value + "_Light.svg",
_resourcesPath + value + "_Gray.svg",
_resourcesPath + value + "_Dark.svg"
}
Current.Resources[key] = content[idx];
}
并像这样使用它:
FillResource("HomePageIcon5", "5", thc);