ListControlDesigner クラス
アセンブリ: System.Design (system.design.dll 内)
構文
Visual Web Designer で、ソース ビューからデザイン ビューに切り替えると、ListControl クラスから派生したコントロールを記述するマークアップのソース コードが解析され、コントロールのデザイン時バージョンがデザイン サーフェイスに作成されます。元のソース ビューに切り替えると、デザイン時のコントロールがマークアップのソース コードに保持され、Web ページのマークアップに反映されます。ListControlDesigner クラスは、ListControl から派生したコントロールを Visual Web Designer でデザイン時に使用できるようにする、デザイナの基本クラスとして機能します。
ListControlDesigner クラスのプロパティは、次の機能を提供します。
-
ActionLists プロパティは、DesignerActionListCollection オブジェクトを返します。一般に、このオブジェクトには、デザイナの継承ツリーの各レベルについて、DesignerActionList オブジェクトから派生したオブジェクトが格納されます。
-
DataTextField プロパティおよび DataValueField プロパティは、ListControl クラスから派生したコントロールの対応するプロパティにアクセスできます。DataTextField および DataValueField はそれぞれ、リスト項目のテキストおよび値の内容を提供する、データ ソースのフィールドを示します。
ListControlDesigner クラスのメソッドは、次の機能を提供します。
-
DataBind メソッドは、ListControl から派生した関連付けられたコントロールを、デザイン時のデータ ソースにバインドします。
-
GetDesignTimeHtml メソッドは、関連付けられたコントロールのデザイン時表示に使用するマークアップを返します。
-
GetSelectedDataSource メソッドは、関連付けられたコントロール コンテナからデザイン時の DataSource コンポーネントを返します。
-
GetResolvedSelectedDataSource メソッドは、コントロール コンテナから DataSource を返し、コントロールのデザイン時の DataMember プロパティに解決されます。
-
Initialize メソッドは、ListControl から派生した関連付けられたコントロールをデザイナで表示およびデザインできるように準備します。
-
OnDataSourceChanged メソッドは、関連付けられたコントロールの DataSource が変更されたときに呼び出されます。
-
PreFilterProperties メソッドは、ListControl から派生した関連付けられたコントロールに対して、プロパティを削除したり、追加したりする場合に使用します。また、その関連付けられたコントロールのプロパティをシャドウする場合にも使用します。
このセクションには、2 つのコード例が用意されています。最初のコード例は、カスタム コントロール デザイナを派生する方法を示しています。2 番目のコード例は、派生したコントロールをデザイナに関連付ける方法を示しています。
SimpleRadioButtonListDesigner という名前のクラスを、ListControlDesigner クラスから継承して作成する方法を次のコード例に示します。SimpleRadioButtonListDesigner クラスは、GetDesignTimeHtml メソッド、Initialize メソッド、および OnDataSourceChanged メソッドをオーバーライドします。SimpleRadioButtonListDesigner クラスは、デザイン サーフェイスに SimpleRadioButtonList コントロールを表示します。
Imports System Imports System.ComponentModel Imports System.Drawing Imports System.Diagnostics Imports System.Web.UI.WebControls Imports System.Web.UI.Design.WebControls Namespace Examples.VB.WebControls.Design ' Create the SimpleRadioButtonListDesigner, which provides ' design-time support for a custom list class. Public Class SimpleRadioButtonListDesigner Inherits ListControlDesigner Private simpleRadioButtonList As SimpleRadioButtonList Private changedDataSource As Boolean ' Create the markup to display the control on the design surface. Public Overrides Function GetDesignTimeHtml() As String Dim designTimeHtml As String = String.Empty ' Create variables to access the control's ' item collection and back color. Dim items As ListItemCollection = simpleRadioButtonList.Items Dim oldBackColor As Color = simpleRadioButtonList.BackColor ' Check the property values and render the markup ' on the design surface accordingly. Try If (Color.op_Equality(oldBackColor, Color.Empty)) Then simpleRadioButtonList.BackColor = Color.Gainsboro End If If (changedDataSource) Then items.Add( _ "Updated to a new data source: " & DataSource & ".") End If designTimeHtml = MyBase.GetDesignTimeHtml() Catch ex As Exception ' Catch any exceptions that occur. MyBase.GetErrorDesignTimeHtml(ex) Finally ' Set the properties back to their original state. simpleRadioButtonList.BackColor = oldBackColor items.Clear() End Try Return designTimeHtml End Function ' GetDesignTimeHtml Public Overrides Sub Initialize(ByVal component As IComponent) ' Ensure that only a SimpleRadioButtonList can be created ' in this designer. Debug.Assert( _ TypeOf component Is SimpleRadioButtonList, _ "An invalid SimpleRadioButtonList control was initialized.") simpleRadioButtonList = CType(component, SimpleRadioButtonList) MyBase.Initialize(component) End Sub ' Initialize ' If the data source changes, set a Boolean variable. Public Overrides Sub OnDataSourceChanged() changedDataSource = True End Sub ' OnDataSourceChanged End Class ' SimpleRadioButtonListDesigner End Namespace ' Examples.VB.WebControls.Design
using System; using System.ComponentModel; using System.Drawing; using System.Diagnostics; using System.Web.UI.WebControls; using System.Web.UI.Design.WebControls; namespace Examples.CS.WebControls.Design { // Create the SimpleRadioButtonListDesigner, which provides // design-time support for a custom list class. public class SimpleRadioButtonListDesigner : ListControlDesigner { SimpleRadioButtonList simpleRadioButtonList; bool changedDataSource; // Create the markup to display the control on the design surface. public override string GetDesignTimeHtml() { string designTimeMarkup = null; // Create variables to access the control // item collection and back color. ListItemCollection items = simpleRadioButtonList.Items; Color oldBackColor = simpleRadioButtonList.BackColor; // Check the property values and render the markup // on the design surface accordingly. try { if (oldBackColor == Color.Empty) simpleRadioButtonList.BackColor = Color.Gainsboro; if (changedDataSource) items.Add("Updated to a new data source: " + DataSource + "."); // Call the base method to generate the markup. designTimeMarkup = base.GetDesignTimeHtml(); } catch (Exception ex) { // Catch any exceptions that occur. designTimeMarkup = GetErrorDesignTimeHtml(ex); } finally { // Set the properties back to their original state. simpleRadioButtonList.BackColor = oldBackColor; items.Clear(); } return designTimeMarkup; } // GetDesignTimeHtml public override void Initialize(IComponent component) { // Ensure that only a SimpleRadioButtonList can be // created in this designer. Debug.Assert( component is SimpleRadioButtonList, "An invalid SimpleRadioButtonList control was initialized."); simpleRadioButtonList = (SimpleRadioButtonList)component; base.Initialize(component); } // Initialize // If the data source changes, set a boolean variable. public override void OnDataSourceChanged() { changedDataSource = true; } // OnDataSourceChanged } // SimpleRadioButtonListDesigner } // Examples.CS.WebControls.Design
RadioButtonList コントロールから SimpleRadioButtonList コントロールを派生するコード例を次に示します。このコード例では、DesignerAttribute クラスを使用して、SimpleRadioButtonList コントロールをそのデザイナである SimpleRadioButtonListDesigner クラスに関連付ける方法を示しています。
Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.ComponentModel Imports System.Security.Permissions Namespace Examples.VB.WebControls.Design ' The SimpleRadioButtonList is a copy of the RadioButtonList. ' It uses the SimpleRadioButtonListDesigner for design-time support. <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(SecurityAction.InheritanceDemand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <DesignerAttribute(GetType(Examples.VB.WebControls.Design. _ SimpleRadioButtonListDesigner))> _ <DataBindingHandler(GetType(Examples.VB.WebControls.Design. _ SimpleRadioButtonListDataBindingHandler))> _ Public Class SimpleRadioButtonList Inherits RadioButtonList End Class ' SimpleRadioButtonList End Namespace ' Examples.VB.WebControls.Design
using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Security.Permissions; namespace Examples.CS.WebControls.Design { // The SimpleRadioButtonList is a copy of the RadioButtonList. // It uses the SimpleRadioButtonListDesigner for design-time support. [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [Designer(typeof(Examples.CS.WebControls.Design. SimpleRadioButtonListDesigner))] [DataBindingHandler(typeof(Examples.CS.WebControls.Design. SimpleRadioButtonListDataBindingHandler))] public class SimpleRadioButtonList : RadioButtonList { } // SimpleRadioButtonList } // Examples.CS.WebControls.Design
- SecurityPermission (アンマネージ コードを呼び出すために必要なアクセス許可) 要求値 : Demand。アクセス許可値 : UnmanagedCode。
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.DataBoundControlDesigner
System.Web.UI.Design.WebControls.ListControlDesigner
System.Web.UI.Design.WebControls.BulletedListDesigner
プラットフォーム
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- ListControlDesigner クラスのページへのリンク