ITeye博客

Silverlight动态设置样式

hao84099 · 2012-02-15 16:29 · web前端 · Web前端 · Silverlight · 样式 · Markdown

1.从页面资源中获取样式并应用

btnTest.Style = (Style)this.Resources["bigbuttonstyle"]

首先,需要创建一个ResourceDictionary对象并提供正确的URI:


ResourceDictionary dictionary = new ResourceDictionary();
dictionary.Source = new Uri("/Test.xaml",UriKind.Relative);

假设样式字典的名字叫Test.xaml,资源字典的编译格式必须为内容(将属性窗口的Build Action设置为Content)。 在配置好ResourceDictionary后,就可以从获取样式并应用它:


btnTest.Style = (Style)dictionary["smallbuttonstyle"];

3.移除样式


btnTest.Style = null

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。