Fun with Silverlight2.0系列之三 -- Skinnable动态换肤效果
2008-10-11 11:41:49 来源:WEB开发网保存这个资源文件为generic.xaml并设置为嵌入式资源。通过删除Custom Tool属性值并设置Build Action为Resource。
这样就可以动态的定义样式和资源文件里的控件模板绑定了。
下面说一说动态定义样式的小技巧,那就是依赖属性(DependencyProperty),它其实是WPF的核心技术点之一,和DependencyObject配合,
提供了WPF中基本的数据存储、访问和通知的机制,具体可参见MSDN上的解说DependencyProperty ,
这篇博客也说的不错WPF中如何实现数据与表示分离。
属性绑定
1 public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register("Foreground", typeof(Brush), typeof(BasicSkin), null);
2 public static readonly DependencyProperty ButtonStyleProperty = DependencyProperty.Register("ButtonStyle", typeof(Style), typeof(BasicSkin), null);
3 public static readonly DependencyProperty ToggleStyleProperty = DependencyProperty.Register("ToggleStyle", typeof(Style), typeof(BasicSkin), null);
4 public static readonly DependencyProperty ToolTipStyleProperty = DependencyProperty.Register("ToolTipStyle", typeof(Style), typeof(BasicSkin), null);
5 public static readonly DependencyProperty CheckBoxStyleProperty = DependencyProperty.Register("CheckBoxStyle", typeof(Style), typeof(BasicSkin), null);
6 public static readonly DependencyProperty RadioStyleProperty = DependencyProperty.Register("RadioStyle", typeof(Style), typeof(BasicSkin), null);
7 public static readonly DependencyProperty TextBoxStyleProperty = DependencyProperty.Register("TextBoxStyle", typeof(Style), typeof(BasicSkin), null);
8 public static readonly DependencyProperty CalendarStyleProperty = DependencyProperty.Register("CalendarStyle", typeof(Style), typeof(BasicSkin), null);
9 public static readonly DependencyProperty DayButtonStyleProperty = DependencyProperty.Register("DayButtonStyle", typeof(Style), typeof(BasicSkin), null);
10 public static readonly DependencyProperty MonthButtonStyleProperty = DependencyProperty.Register("MonthButtonStyle", typeof(Style), typeof(BasicSkin), null);
11 public static readonly DependencyProperty DatePickerStyleProperty = DependencyProperty.Register("DatePickerStyle", typeof(Style), typeof(BasicSkin), null);
12 public static readonly DependencyProperty LinkStyleProperty = DependencyProperty.Register("LinkStyle", typeof(Style), typeof(BasicSkin), null);
13 public static readonly DependencyProperty DataGridStyleProperty = DependencyProperty.Register("DataGridStyle", typeof(Style), typeof(BasicSkin), null);
14 public static readonly DependencyProperty ColumnHeaderStyleProperty = DependencyProperty.Register("ColumnHeaderStyle", typeof(Style), typeof(BasicSkin), null);
15 public static readonly DependencyProperty RowHeaderStyleProperty = DependencyProperty.Register("RowHeaderStyle", typeof(Style), typeof(BasicSkin), null);
16 public static readonly DependencyProperty RowStyleProperty = DependencyProperty.Register("RowStyle", typeof(Style), typeof(BasicSkin), null);
17
18
19 /**//// <summary>
20 /// Expose our background
21 /// </summary>
22 public Brush Foreground
23 {
24 get { return (Brush)GetValue(ForegroundProperty); }
25 set { SetValue(ForegroundProperty, value); }
26 }
27
28 /**//// <summary>
29 /// Expose our button style
30 /// </summary>
31 public Style ButtonStyle
32 {
33 get { return (Style)GetValue(ButtonStyleProperty); }
34 set { SetValue(ButtonStyleProperty, value); }
35 }
36
37 /**//// <summary>
38 /// Expose our toggle button style
39 /// </summary>
40 public Style ToggleStyle
41 {
42 get { return (Style)GetValue(ToggleStyleProperty); }
43 set { SetValue(ToggleStyleProperty, value); }
44 }
45
46 /**//// <summary>
47 /// Expose our ToolTip Style
48 /// </summary>
49 public Style ToolTipStyle
50 {
51 get { return (Style)GetValue(ToolTipStyleProperty); }
52 set { SetValue(ToolTipStyleProperty, value); }
53 }
54
55 /**//// <summary>
56 /// Expose our button style
57 /// </summary>
58 public Style CheckBoxStyle
59 {
60 get { return (Style)GetValue(CheckBoxStyleProperty); }
61 set { SetValue(CheckBoxStyleProperty, value); }
62 }
63
64 /**//// <summary>
65 /// Expose our toggle button style
66 /// </summary>
67 public Style RadioStyle
68 {
69 get { return (Style)GetValue(RadioStyleProperty); }
70 set { SetValue(RadioStyleProperty, value); }
71 }
72
73 /**//// <summary>
74 /// Expose our ToolTip Style
75 /// </summary>
76 public Style TextBoxStyle
77 {
78 get { return (Style)GetValue(TextBoxStyleProperty); }
79 set { SetValue(TextBoxStyleProperty, value); }
80 }
81
82 public Style CalendarStyle
83 {
84 get { return (Style)GetValue(CalendarStyleProperty); }
85 set { SetValue(CalendarStyleProperty, value); }
86 }
87 public Style DayButtonStyle
88 {
89 get { return (Style)GetValue(DayButtonStyleProperty); }
90 set { SetValue(DayButtonStyleProperty, value); }
91 }
92 public Style MonthButtonStyle
93 {
94 get { return (Style)GetValue(MonthButtonStyleProperty); }
95 set { SetValue(MonthButtonStyleProperty, value); }
96 }
97 public Style DatePickerStyle
98 {
99 get { return (Style)GetValue(DatePickerStyleProperty); }
100 set { SetValue(DatePickerStyleProperty, value); }
101 }
102 public Style LinkStyle
103 {
104 get { return (Style)GetValue(LinkStyleProperty); }
105 set { SetValue(LinkStyleProperty, value); }
106 }
107
108 public Style DataGridStyle
109 {
110 get { return (Style)GetValue(DataGridStyleProperty); }
111 set { SetValue(DataGridStyleProperty, value); }
112 }
113 public Style ColumnHeaderStyle
114 {
115 get { return (Style)GetValue(ColumnHeaderStyleProperty); }
116 set { SetValue(ColumnHeaderStyleProperty, value); }
117 }
118 public Style RowHeaderStyle
119 {
120 get { return (Style)GetValue(RowHeaderStyleProperty); }
121 set { SetValue(RowHeaderStyleProperty, value); }
122 }
123 public Style RowStyle
124 {
125 get { return (Style)GetValue(RowStyleProperty); }
126 set { SetValue(RowStyleProperty, value); }
127 }
Tags:Fun with Silverlight
编辑录入:爽爽 [复制链接] [打 印]- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››Silverlight for Symbian
- ››Silverlight3系列(四)数据绑定 Data Binding 1
- ››silverlight2 游戏 1 你能坚持多少秒
- ››Silverlight开发实践--PicZoomShow
- ››Silverlight自定义控件开发 - 令人懊恼的OnApplyT...
- ››Silverlight 2 RTW中ToolTipService.ToolTip不继承...
更多精彩
赞助商链接