HierarchicalDataBoundControlDesigner クラス
アセンブリ: System.Design (system.design.dll 内)


デザイナ ホストで、ソース ビューからデザイン ビューに切り替えると、HierarchicalDataBoundControl 抽象クラスから派生したコントロールを記述するマークアップのソース コードが解析され、コントロールのデザイン時バージョンがデザイン サーフェイスに作成されます。元のソース ビューに切り替えると、デザイン時のコントロールがマークアップのソース コードに保持され、Web ページのマークアップに反映されます。HierarchicalDataBoundControlDesigner クラスは、HierarchicalDataBoundControl から派生したコントロールを、デザイン時にデザイナ ホストで使用できるようにします。
HierarchicalDataBoundControlDesigner クラスのプロパティは、次の機能を提供します。
-
ActionLists プロパティは、DesignerActionListCollection オブジェクトを返します。一般にこのオブジェクトには、デザイナの継承ツリーの各レベルについて、DesignerActionList クラスから派生したオブジェクトが格納されます。
-
DataSourceDesigner プロパティが定義されている場合、このプロパティからデータ ソースのデザイナにアクセスできます。
-
DesignerView プロパティは、関連付けられたコントロールにバインドされるデータ ソースの既定のビューを取得します。
-
UseDataSourcePickerActionList プロパティは、データ ソースの選択と作成に使用される既定のアクション リストをコントロールが表示するかどうかを判断します。
HierarchicalDataBoundControlDesigner クラスのメソッドは、次の機能を提供します。
-
DataBind メソッドは、HierarchicalDataBoundControl クラスから派生した関連付けられたコントロールを、デザイン時のデータ ソースにバインドします。
-
DisconnectFromDataSource メソッドは、現在のデータ ソースから接続を解除するために必要なアクションを実行します。
-
GetDesignTimeDataSource メソッドは、デザイン時に、関連付けられたコントロールで使用できるデータ ソースを取得します。
-
GetSampleDataSource メソッドは、デザイン時に、関連付けられたコントロールに使用できるサンプル データ ソースを構築します。
-
PreFilterProperties メソッドは、HierarchicalDataBoundControl クラスから派生した関連付けられたコントロールに対して、プロパティを削除したり、追加したりする場合に使用します。また、その関連付けられたコントロールのプロパティをシャドウする場合にも使用します。

HierarchicalDataBoundControlDesigner クラスを拡張し、HierarchicalDataBoundControl コントロールから派生したコントロールの外観をデザイン時に変更するコード例を次に示します。
この例では、MyHierarchicalDataBoundControl クラスを HierarchicalDataBoundControl から派生させています。MyHierarchicalDataBoundControl クラスは、単に HierarchicalDataBoundControl のコピーです。また、この例では、HierarchicalDataBoundControlDesigner クラスから MyHierarchicalDataBoundControlDesigner クラスを派生させ、MyHierarchicalDataBoundControlDesigner の DesignerAttribute オブジェクトを MyHierarchicalDataBoundControl クラスに配置します。
MyHierarchicalDataBoundControlDesigner は、PreFilterProperties メソッドをオーバーライドし、デザイン時に、[プロパティ] グリッドに NamingContainer プロパティを表示します。デザイン時のマークアップが null 参照 (Visual Basic では Nothing) または Empty である場合、またはデザイン時のマークアップが空の <span> ブロックである場合 (つまり、<span ...> タグと </span> タグの間に内部マークアップがない場合) は、GetDesignTimeHtml メソッドをオーバーライドしてプレースホルダのマークアップを生成します。
Imports System Imports System.IO Imports System.Web Imports System.Drawing Imports System.Web.UI.WebControls Imports System.Web.UI.Design.WebControls Imports System.Collections Imports System.ComponentModel Imports System.Security.Permissions Namespace Examples.VB.WebControls.Design ' The MyHierarchicalDataBoundControl is a copy of the ' HierarchicalDataBoundControl. <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(SecurityAction.InheritanceDemand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <Designer(GetType(Examples.VB.WebControls.Design. _ MyHierarchicalDataBoundControlDesigner))> _ Public Class MyHierarchicalDataBoundControl Inherits HierarchicalDataBoundControl End Class ' MyHierarchicalDataBoundControl ' Override members of the HierarchicalDataBoundControlDesigner. <ReflectionPermission(SecurityAction.Demand, Flags:=ReflectionPermissionFlag.MemberAccess)> _ Public Class MyHierarchicalDataBoundControlDesigner Inherits HierarchicalDataBoundControlDesigner Private Const bracketClose As String = ">" Private Const spanOpen As String = "<SPAN" Private Const spanClose As String = "</SPAN>" ' Return the markup for a placeholder, if the inner markup is empty. ' For brevity, the code that is used to detect embedded white_space ' in the tags is not shown. Public Overrides Function GetDesignTimeHtml() As String ' Get the design-time markup from the base method. Dim markup As String = MyBase.GetDesignTimeHtml() ' If the markup is null or empty, return the markup ' for the placeholder. If markup Is Nothing OrElse markup = String.Empty Then Return GetEmptyDesignTimeHtml() End If ' Make the markup uniform case so that the IndexOf will work. Dim markupUC As String = markup.ToUpper() Dim charX As Integer ' Look for a <span ...> tag. charX = markupUC.IndexOf(spanOpen) If charX >= 0 Then ' Find closing bracket of span open tag. charX = markupUC.IndexOf(bracketClose, charX + spanOpen.Length) If charX >= 0 Then ' If the inner markup of <span ...></span> is empty, ' return the markup for a placeholder. If String.Compare(markupUC, charX + 1, _ spanClose, 0, spanClose.Length) = 0 Then Return GetEmptyDesignTimeHtml() End If End If End If ' Return the original markup, if the inner markup is not empty. Return markup End Function ' GetDesignTimeHtml ' Shadow the control properties with design-time properties. Protected Overrides Sub PreFilterProperties( _ ByVal properties As IDictionary) Dim namingContainer As String = "NamingContainer" ' Call the base method first. MyBase.PreFilterProperties(properties) ' Make the NamingContainery visible in the Properties grid. Dim selectProp As PropertyDescriptor = _ CType(properties(namingContainer), PropertyDescriptor) properties(namingContainer) = _ TypeDescriptor.CreateProperty(selectProp.ComponentType, _ selectProp, BrowsableAttribute.Yes) End Sub ' PreFilterProperties End Class ' MyHierarchicalDataBoundControlDesigner End Namespace ' Examples.VB.WebControls.Design
using System; using System.IO; using System.Web; using System.Drawing; using System.Web.UI.WebControls; using System.Web.UI.Design.WebControls; using System.Collections; using System.ComponentModel; using System.Security.Permissions; namespace Examples.CS.WebControls.Design { // The MyHierarchicalDataBoundControl is a copy of the // HierarchicalDataBoundControl. [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [Designer(typeof(Examples.CS.WebControls.Design. MyHierarchicalDataBoundControlDesigner))] public class MyHierarchicalDataBoundControl : HierarchicalDataBoundControl { } // MyHierarchicalDataBoundControl // Override members of the ierarchicalDataBoundControlDesigner. [ReflectionPermission(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)] public class MyHierarchicalDataBoundControlDesigner : HierarchicalDataBoundControlDesigner { const string bracketClose = ">"; const string spanOpen = "<SPAN"; const string spanClose = "</SPAN>"; // Return the markup for a placeholder, if the inner markup is empty. // For brevity, the code that is used to detect embedded white_space // in the tags is not shown. public override string GetDesignTimeHtml() { // Get the design-time markup from the base method. string markup = base.GetDesignTimeHtml(); // If the markup is null or empty, return the markup // for the placeholder. if(markup == null || markup == string.Empty) return GetEmptyDesignTimeHtml(); // Make the markup uniform case so that the IndexOf will work. string MARKUP = markup.ToUpper(); int charX; // Look for a <span ...> tag. if ((charX = MARKUP.IndexOf(spanOpen)) >= 0) { // Find closing bracket of span open tag. if ((charX = MARKUP.IndexOf(bracketClose, charX+spanOpen.Length)) >= 0) { // If the inner markup of <span ...></span> is empty, // return the markup for a placeholder. if (string.Compare(MARKUP, charX + 1, spanClose, 0, spanClose.Length) == 0) return GetEmptyDesignTimeHtml(); } } // Return the original markup, if the inner markup is not empty. return markup; } // Shadow the control properties with design-time properties. protected override void PreFilterProperties(IDictionary properties) { string namingContainer = "NamingContainer"; // Call the base method first. base.PreFilterProperties(properties); // Make the NamingContainery visible in the Properties grid. PropertyDescriptor selectProp = (PropertyDescriptor)properties[namingContainer]; properties[namingContainer] = TypeDescriptor.CreateProperty(selectProp.ComponentType, selectProp, BrowsableAttribute.Yes); } // PreFilterProperties } // MyHierarchicalDataBoundControlDesigner } // Examples.CS.WebControls.Design

System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
System.Web.UI.Design.WebControls.BaseDataBoundControlDesigner
System.Web.UI.Design.WebControls.HierarchicalDataBoundControlDesigner
System.Web.UI.Design.WebControls.MenuDesigner
System.Web.UI.Design.WebControls.TreeViewDesigner


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- HierarchicalDataBoundControlDesigner クラスのページへのリンク