如何在Silverlight 4中动态加载用户定义的样式 [英] how to dynamically load user defined styles in silverlight 4
问题描述
大家好,
感谢所有的巨大回应.
这次我在样式方面遇到问题.
我必须使用styles.i希望它们在诸如combo之类的事件发生时能够动态加载它们.当我选择用户定义的theme1时,所有控件均采用主题一的样式;当我选择theme2时,则所有控件均采用各自的样式.我既可以为一种样式设置样式,也可以动态使用所有silverlight主题.但是对于选择和设置特定主题,我不知道该怎么做.
对身体有些帮助.
我已经在下面编写了这段代码,并找到了一个说
的异常
已经添加了具有相同键的项目".
Hi All,
thanks for all the huge responses.
This time i am having a problem in styles.
I have to styles.i want them to get loaded them dynamically on fire of an event like combo. when i select user defined theme1 then all the controls takes the styles of theme one and when i select theme2 then all the controls takes the respective styles. i am able to set the style for one style as well as i am able to use all the silverlight theme dynamically.but for selecting and setting a particular theme i dont know how to do that.
Some body pls help.
i have written this code below and finding an exception which say
"An item with the same key has already been added".
void GetThemes(string s)<br />
{<br />
StreamResourceInfo sri = Application.GetResourceStream(new Uri(string.Format("Test;component/{0}.xaml",s), UriKind.Relative));<br />
StreamReader sr = new StreamReader(sri.Stream);<br />
XElement element = XElement.Parse(sr.ReadToEnd());<br />
List<Theme> themeSettings = new List<Theme>();<br />
IEnumerable c1 = from el in element.Elements() select el;<br />
<br />
foreach (XElement ele in c1)<br />
themeSettings.Add(new Theme { Key = ele.FirstAttribute.Value, Value= ele.ToString() });<br />
IsolatedStorageSettings.ApplicationSettings.Add(string.Format("{0}Theme",s), themeSettings); <br />
}
例外出现在最后一行,即
IsolatedStorageSettings.ApplicationSettings.Add(string.Format("{0} Theme",s),themeSettings);
the exception comes in the last line ie
IsolatedStorageSettings.ApplicationSettings.Add(string.Format("{0}Theme",s), themeSettings);
推荐答案
关于如何执行此操作的教程非常出色此处动态样式 [
There is an excellent tutorial on how to do this here Dynamic Styles[^].
Hope this helps
这篇关于如何在Silverlight 4中动态加载用户定义的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!