【发布时间】:2018-02-06 05:01:35
【问题描述】:
我正在创建一个 Xamarin.Forms 应用程序。我无法从后面的代码中设置样式。以下代码在我页面的构造函数中。
Style greenButton = new Style(typeof(Button))
{
Setters =
{
new Setter{Property = Button.BackgroundColorProperty, Value = Color.Green },
new Setter{Property = Button.TextColorProperty, Value = Color.Red}
}
};
Resources = new ResourceDictionary();
Resources.Add(greenButton);
Button createSL = new Button();
createSL.Text = "Create Stack Layout";
createSL.Style = (Style) Resources["greenButton"];
上面的代码给出了这个error message。
A Key not found 异常声明“greenButton”不存在 在字典里。
但我已经完成了 Xamarin.Forms 文档中提到的所有操作。请帮我解决它!
【问题讨论】:
标签: c# xamarin xamarin.forms resourcedictionary