av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

ASP.NET控件設計時操作列表與模板編輯淺析

ASP.NET控件設計時操作列表與模板編輯的基本內容:

成都創(chuàng)新互聯(lián)主營當涂網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,手機APP定制開發(fā),當涂h5小程序設計搭建,當涂網(wǎng)站營銷推廣歡迎當涂等地區(qū)企業(yè)咨詢

ASP.NET控件設計時操作列表與模板編輯一.智能標記

先看一張圖.

GridView右側的小三角可以很輕松的幫助我們設置常用的屬性,如下面的啟動分頁,啟用排序等,通過這樣的方式我們可以很快的完成工作。我們稱這樣的任務菜單為智能標記.

下面來看看ASP.NET控件設計時操作列表與模板編輯如何實現(xiàn)

1.重寫ControlDesigner的ActionLists屬性

你必須重寫這個屬性,返回你自定義的智能標記集合(即DesignerActionListCollection),這里假設CustomControlActionList為自定義的智能

 
 
 
  1. public class SampleControlDesigner : ControlDesigner  
  2. {  
  3.     public SampleControlDesigner()  
  4.         : base()  
  5.     {  
  6.     }  
  7.  
  8.     //創(chuàng)建一個自定義操作列表集合  
  9.     public override DesignerActionListCollection ActionLists  
  10.     {  
  11.         get 
  12.         {  
  13.             DesignerActionListCollection actionLists = new DesignerActionListCollection();  
  14.             actionLists.Add(new CustomControlActionList(this));  
  15.  
  16.             return actionLists;  
  17.         }  
  18.     }    

2.CustomControlActionList 自定義項列表

2.1項列表分類

(1)標題面板

(2)屬性面板

(3)方法面板

類圖如下

看個效果圖,你就明白怎么回事了

2.2實現(xiàn)

(1)繼承DesignerActionList類,重寫GetSortedActionItems方法添加自定義項面板集合,即2.1的三種項面板

 
 
 
  1. public override DesignerActionItemCollection GetSortedActionItems()  
  2. {  
  3.     if (items == null)  
  4.     {  
  5.         items = new DesignerActionItemCollection();  
  6.         // 添加標題面板  
  7.         items.Add(new DesignerActionHeaderItem("快速設置面板測試:"));  
  8.         //添加屬性相關面板  
  9.         items.Add(new DesignerActionPropertyItem("Visible",  
  10.                  "是否顯示"));  
  11.         items.Add(new DesignerActionPropertyItem("Width",  
  12.                 "設置寬度"));  
  13.         items.Add(new DesignerActionPropertyItem("Height",  
  14.                "設置高度"));  
  15.         // 添加方法相關面板  
  16.  
  17.         items.Add(new DesignerActionMethodItem(this, "FormatBlue", "定義背景為藍色", true));  
  18.         items.Add(new DesignerActionMethodItem(this, "FormatRed", "定義背景為紅色", true));  
  19.         items.Add(new DesignerActionMethodItem(this, "FormatWhite", "定義背景為白色", true));  
  20.           
  21.     }  
  22.     return items;  

(2)屬性,方法項面板的實現(xiàn)

如果你設置屬性的話,則必須在CustomControlActionList定義屬性,方法也相同,代碼如下

 
 
 
  1. #region 自定義方法  
  2.  
  3.         public void FormatBlue()  
  4.         {  
  5.             SampleControl ctrl = (SampleControl)_parent.Component;  
  6.             TransactedChangeCallback toCall = new TransactedChangeCallback(DoFormat);  
  7.             ControlDesigner.InvokeTransactedChange(ctrl, toCall, "FormatBlue", "FormatBlue");  
  8.         }  
  9.  
  10.         public void FormatRed()  
  11.         {  
  12.             SampleControl ctrl = (SampleControl)_parent.Component;  
  13.             TransactedChangeCallback toCall = new TransactedChangeCallback(DoFormat);  
  14.             ControlDesigner.InvokeTransactedChange(ctrl, toCall, "FormatRed", "FormatRed");  
  15.         }  
  16.  
  17.         public void FormatWhite()  
  18.         {  
  19.             SampleControl ctrl = (SampleControl)_parent.Component;  
  20.             //定義委托  
  21.             TransactedChangeCallback toCall = new TransactedChangeCallback(DoFormat);  
  22.             ControlDesigner.InvokeTransactedChange(ctrl, toCall, "FormatWhite", "FormatWhite");  
  23.         }  
  24.  
  25.         #endregion 
 
 
 
  1. #region 自定義屬性  
  2.  
  3.         public bool Visible  
  4.         {  
  5.             get 
  6.             {  
  7.                 SampleControl ctrl = (SampleControl)_parent.Component;  
  8.                 return ctrl.Visible;  
  9.             }  
  10.             set 
  11.             {  
  12.                     PropertyDescriptor propDesc = TypeDescriptor.GetProperties(_parent.Component)["Visible"];  
  13.                     propDesc.SetValue(_parent.Component, value);  
  14.  
  15.             }  
  16.         }  
  17.  
  18.         public Unit Width  
  19.         {  
  20.             get 
  21.             {  
  22.                 SampleControl ctrl = (SampleControl)_parent.Component;  
  23.                 return ctrl.Width;  
  24.             }  
  25.             set 
  26.             {  
  27.                 PropertyDescriptor propDesc = TypeDescriptor.GetProperties(_parent.Component)["Width"];  
  28.                 propDesc.SetValue(_parent.Component, value);  
  29.             }  
  30.         }  
  31.  
  32.         public Unit Height  
  33.         {  
  34.             get 
  35.             {  
  36.                 SampleControl ctrl = (SampleControl)_parent.Component;  
  37.                 return ctrl.Height;  
  38.             }  
  39.             set 
  40.             {  
  41.                 PropertyDescriptor propDesc = TypeDescriptor.GetProperties(_parent.Component)["Height"];  
  42.                 propDesc.SetValue(_parent.Component, value);  
  43.             }  
  44.         }  
  45.  
  46.         #endregion  
  47.  
  48.         public bool DoFormat(object arg)  
  49.         {  
  50.             SampleControl ctl = (SampleControl)_parent.Component;  
  51.             string fmt = (string)arg;  
  52.  
  53.             PropertyDescriptor backColorProp = TypeDescriptor.GetProperties(ctl)["BackColor"];  
  54.  
  55.             switch (fmt)  
  56.             {  
  57.                 case "FormatBlue":  
  58.                     backColorProp.SetValue(ctl, Color.Blue);  
  59.                     break;  
  60.                 case "FormatRed":  
  61.  
  62.                     backColorProp.SetValue(ctl, Color.Red);  
  63.                     break;  
  64.                 case "FormatWhite":  
  65.                     backColorProp.SetValue(ctl, Color.White);  
  66.                     break;  
  67.             }  
  68.  
  69.             //刷新設計時html標記  
  70.             _parent.UpdateDesignTimeHtml();  
  71.  
  72.             return true;  
  73.         } 

以上步驟完成以后就大功告成了,接著則與相關控件關聯(lián)起來就可以了,效果圖在上面已經看過了.

[DesignerAttribute(typeof(SampleControlDesigner))]

ASP.NET控件設計時操作列表與模板編輯二.模板編輯器

上面的模板編輯界面相信大家都很熟悉吧.設置支持怎么少的了模板呢.設置時模板編輯實現(xiàn)比較簡單,下面來看下如何實現(xiàn)

這里自定義的模板控件不再列出

1.重寫ControlDesigner類的TemplateGroups返回自定義模板組集合即(TemplateGroupCollection)

添加步驟跟表格的添加類似,td add tr然后table add td

模板則是TemplateGroup add TemplateDefinition 然后TemplateGroupCollection add TemplateGroup

代碼如下

 
 
 
  1. public override TemplateGroupCollection TemplateGroups  
  2.         {  
  3.             get 
  4.             {  
  5.  
  6.                 if (col == null)  
  7.                 {  
  8.                     col = base.TemplateGroups;  
  9.  
  10.                     TemplateGroup tempGroup;  
  11.                     TemplateDefinition tempDef;  
  12.                     TemplateGroupsSample ctl;  
  13.  
  14.                     ctl = (TemplateGroupsSample)Component;  
  15.  
  16.                     // 創(chuàng)建模板分組一  
  17.                     tempGroup = new TemplateGroup("模板A組");  
  18.  
  19.                     //提供在設置時編輯模板  
  20.                     tempDef = new TemplateDefinition(this, "Template A1",  
  21.                         ctl, "Template1", false);  
  22.  
  23.                     tempGroup.AddTemplateDefinition(tempDef);  
  24.  
  25.                    
  26.                     tempDef = new TemplateDefinition(this, "Template A2",  
  27.                         ctl, "Template2", false);  
  28.  
  29.                     tempGroup.AddTemplateDefinition(tempDef);  
  30.  
  31.            
  32.                     col.Add(tempGroup);  
  33.  
  34.                     // 創(chuàng)建模板分組二  
  35.                     tempGroup = new TemplateGroup("模板B組");  
  36.                     tempDef = new TemplateDefinition(this, "Template B1",  
  37.                         ctl, "Template3", true);  
  38.                     tempGroup.AddTemplateDefinition(tempDef);  
  39.                     tempDef = new TemplateDefinition(this, "Template B2",  
  40.                         ctl, "Template4", true);  
  41.                     tempGroup.AddTemplateDefinition(tempDef);  
  42.                     col.Add(tempGroup);  
  43.                 }  
  44.  
  45.                 return col;  
  46.             }  
  47.         } 

這里注意TemplateDefinition構造函數(shù)的***一個屬性,true則在設計時編輯只能添加服務器控件

2.初始化啟用設計時模板編輯

我們還需要在Initialize方法中調用SetViewFlags方法啟用設計時模板編輯

 
 
 
  1. public override void Initialize(IComponent component)  
  2. {  
  3.    
  4.     base.Initialize(component);  
  5.    
  6.     SetViewFlags(ViewFlags.TemplateEditing, true);  

3.提供默認矩形標識符,為控件提供說明

如下圖,DataList默認情況下給予如下提示

我們可以通過重寫GetDesignTimeHtml方法調用CreatePlaceHolderDesignTimeHtml方法創(chuàng)建一個矩形標識符來實現(xiàn)

 
 
 
  1. public override string GetDesignTimeHtml()  
  2. {  
  3.     return CreatePlaceHolderDesignTimeHtml("右擊或選擇編輯模板面板來編輯模板內容");  

好了,完成了,接著要做的就是與相關模板控件關聯(lián)起來了

平時大家都太忙了,上面功能有跟沒有沒多大關系,不過常用控件屬性和功能,有設計時支持一定會讓使用的更加有效.

ASP.NET控件設計時操作列表與模板編輯的相關內容就向你介紹到這里,希望對你了解ASP.NET控件設計時操作列表與模板編輯有所幫助。


網(wǎng)站題目:ASP.NET控件設計時操作列表與模板編輯淺析
文章分享:http://uogjgqi.cn/article/ccoehcg.html
掃二維碼與項目經理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流