WEB开发网
开发学院图形图像Flash Silverlight学习笔记三:如何自定义DataGrid的Hea... 阅读

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(Text

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

上一页  1 2 3 4 5  下一页

Tags:Silverlight 学习 笔记

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接