首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

為 ASP.NET 控件添加設計時支援:IntelliSense、屬性瀏覽器、工具箱、HTML 視圖與自定義設計器完整指南

     編輯:關於ASP.NET

優秀的控件不僅執行時強大,更要在 Visual Studio 設計時提供一流體驗。本文系統介紹五大設計時支援類型及其實作機制。

五大設計時支援類型

支援類型實現機制關鍵技術
程式碼編輯器 IntelliSenseIDE 讀取組件中繼資料編譯組件放入 Bin 目錄即可
設計檢視屬性瀏覽器TypeConverter + 中繼資料屬性Category、Description、Editor、TypeConverter
工具箱拖放支援ToolboxBitmapAttribute嵌入 16x16 位圖資源
HTML 視圖屬性瀏覽器XSD 結構描述 + VS 註釋自定義 .xsd,指定編輯器、預設值
HTML 編輯器 IntelliSense同 HTML 視圖 XSDvs:toolboxitem、vs:property 等註釋

進階:自定義設計器

  • 繼承 ControlDesigner,重寫 GetDesignTimeHtml 輸出設計時專用 HTML(如顯示未繫結資料的佔位提示)。
  • 透過 DesignerAttribute 綁定:[Designer(typeof(MyControlDesigner))]。
  • 支援智慧標籤:實作 DesignerActionListCollection,提供常用任務捷徑。

Blog 控件完整範例結構

// Blog.cs - 控件本體
[Designer(typeof(BlogDesigner))]
[ToolboxBitmap(typeof(Blog), "Blog.bmp")]
public class Blog : WebControl { ... }

// BlogDesigner.cs - 設計器
public class BlogDesigner : ControlDesigner
{
    public override string GetDesignTimeHtml() { ... }
    public override DesignerActionListCollection ActionLists { get { ... } }
}

// Blog.xsd - HTML 視圖結構描述
<xs:schema ...>
  <xs:element name="Blog" vs:toolboxitem="true"> ... </xs:element>
</xs:schema>

部署檢查清單

  1. 組件強名簽署並安裝至 GAC(可選,但利於共用)。
  2. 2. 設計時組件(Designer、XSD)置於 Visual Studio 安裝目錄\Common7\IDE\PublicAssemblies 或專案引用。 3. 在 web.config 註冊標記前綴:<add tagPrefix="cc" namespace="MyControls" assembly="MyControls" />。

投資設計時體驗,能讓使用者像操作原生控件一樣高效使用你的控件,是商業級控件的必修課。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved