我试图从C#中检索资源字典(Styles.xaml)中预定义的纯色画笔。Silverlight 4 - 在运行时从资源字典中检索纯色笔刷?
的问题是,当我运行下面的代码没有任何反应:
private void LinkContinue_MouseEnter(object sender, MouseEventArgs e)
{
this.LinkContinue.Background = (SolidColorBrush)Resources["HoverColorBrush"];
}
但是如果我在代码中设置背景明确它运行良好:
private void LinkContinue_MouseLeave(object sender, MouseEventArgs e)
{
this.LinkContinue.Background = new SolidColorBrush(Colors.Gray);
}
任何想法?
你检查了铸造成功返回一个solicColorBrush? 或者可能有抛出的异常? – MichaelS
是'Resources [“HoverColorBrush”]'null'? – Gabe