2010-09-02 93 views
0

如何将字符串字面值“ErrorLabel”替换为第二行中的字符串变量样式? FYI ..样式名称将被存储在一个xml文件中。获取字符串变量的值

string style = "ErrorLabel"; 
Style styItem = LayoutRoot.Resources["ErrorLabel"] as Style; 
fld.Settings.CellValuePresenterStyle = styItem; 

回答

2

这应做到:

string style = "ErrorLabel"; 
Style styItem = LayoutRoot.Resources[style] as Style; 
fld.Settings.CellValuePresenterStyle = styItem; 
+0

谢谢!现在起作用了,我感到很蠢!出于某种原因,尽管ResourceDictionary的关键字是类型对象,编译器仍然说我不能使用变量! – GBackMania 2010-09-02 16:24:07