Silverlight学习笔记三:如何自定义DataGrid的Header
2008-12-30 11:53:52 来源:WEB开发网1 [TemplatePart(Name=GridHeader.HeaderTextElement,Type=typeof(FrameworkElement))]
2 [TemplatePart(Name=GridHeader.FilterTextElement,Type=typeof(TextBox))]
3 publicclassGridHeader:Control
4 {
5 publicdelegatevoidHeaderClickEvent(stringfieldname);
6 publiceventHeaderClickEventOnSort;
7
8 publicdelegatevoidFilterTextEvent(stringfieldname,stringfiltertext);
9 publiceventFilterTextEventOnFilter;
10
11 protectedconststringHeaderTextElement="btnHeaderText";
12 protectedconststringFilterTextElement="txtFilerText";
13
14 Buttonbtn_header;
15 TextBoxfilterText;
16
17 #regionConstructor
18 publicGridHeader()
19 {
20 this.DefaultStyleKey=typeof(GridHeader);
21 }
22 #endregion
23
24 #regionHeaderText
25 ///<summary>
26 ///IdentifiestheHeaderTextdependencyproperty.
27 ///</summary>
28 publicstaticreadonlyDependencyPropertyHeaderTextProperty=DependencyProperty.Register("HeaderText",typeof(string),typeof(GridHeader),null);
29
30 ///<summary>
31 ///GetsorsetstheHeaderTextpossibleValueoftheintobject.
32 ///</summary>
33 publicstringHeaderText
34 {
35 get{return(string)GetValue(HeaderTextProperty);}
36 set{SetValue(HeaderTextProperty,value);}
37 }
38 #endregionHeaderText
39
40 #regionFilterText
41
42 ///<summary>
43 ///IdentifiestheFilterTextdependencyproperty.
44 ///</summary>
45 publicstaticreadonlyDependencyPropertyFilterTextProperty=DependencyProperty.Register("FilterText",typeof(string),typeof(GridHeader),null);
46
47 ///<summary>
48 ///GetsorsetstheFilterTextpossibleValueofthestringobject.
49 ///</summary>
50 publicstringFilterText
51 {
52 get{return(string)GetValue(FilterTextProperty);}
53 set{SetValue(FilterTextProperty,value);}
54 }
55 #endregionFilterText
56
57 #regionFieldText
58 publicstaticDependencyPropertyFieldTextProperty=DependencyProperty.Register("FieldText",typeof(string),typeof(GridHeader),null);
59 publicstringFieldText
60 {
61 get{return(string)GetValue(FieldTextProperty);}
62 set{SetValue(FieldTextProperty,value);}
63 }
64
65 #endregion
66
67 publicoverridevoidOnApplyTemplate()
68 {
69 base.OnApplyTemplate();
70 StackPanelsp=this.GetTemplateChild("LayoutRoot")asStackPanel;
71
72 btn_header=sp.Children[0]asButton;
73 filterText=sp.Children[1]asTextBox;
74
75 if(this.filterText!=null)
76 this.filterText.LostFocus+=newRoutedEventHandler(filterText_LostFocus);
77 if(this.btn_header!=null)
78 this.btn_header.Click+=newRoutedEventHandler(header_Click);
79 }
80
81 voidheader_Click(objectsender,RoutedEventArgse)
82 {
83 OnSort(FieldText);
84 }
85
86 voidfilterText_LostFocus(objectsender,RoutedEventArgse)
87 {
88 OnFilter(FieldText,filterText.Text.Trim());
89 }
90
Tags:Silverlight 学习 笔记
编辑录入:爽爽 [复制链接] [打 印]- ››笔记本蓝屏错误代码0X0000000A故障处理
- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››学习网站日志分析:网站日志分析各项指标
- ››学习:Ylmf OS安装全过程(视频)
- ››学习了SEO可以做哪些事
- ››学习 Linux,101: 保持文件系统的完整性
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››学习Java,C等程序开发的十大秘诀
更多精彩
赞助商链接