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


ビジュアル デザイナでソース ビューからデザイン ビューに切り替えると、DetailsView コントロールを記述するマークアップ ソース コードが解析され、コントロールのデザイン時バージョンがデザイン サーフェイスに作成されます。元のソース ビューに切り替えると、デザイン時のコントロールがマークアップのソース コードに保持され、Web ページのマークアップに反映されます。
DetailsViewDesigner クラスのプロパティは、次の機能を提供します。
-
ActionLists プロパティは、DesignerActionListCollection オブジェクトを返します。このオブジェクトには、デザイナの継承ツリーの各レベルについて、DesignerActionList クラスから派生したオブジェクトが格納されます。
-
AutoFormats プロパティは、[オートフォーマット] ダイアログ ボックスで表示するための書式指定スキームのコレクションを返します。
-
TemplateGroups プロパティは、関連付けられた DetailsView コントロールとトップレベルの DetailsView テンプレートについて、フィールド グループのコレクションを返します。
-
UsePreviewControl プロパティは、常に true を返します。デザイナは、関連付けられた DetailsView コントロールの一時的なコピーを作成して、デザイン時のマークアップを生成します。
DetailsViewDesigner クラスのメソッドは、次の機能を提供します。
-
DataBind メソッドは、関連付けられた DetailsView コントロールをデザイン時のデータ ソースにバインドします。
-
GetDesignTimeHtml メソッドは、デザイン時に、関連する DetailsView のレンダリングに使用するマークアップを返します。
-
Initialize メソッドは、関連付けられた DetailsView をデザイナで表示、編集、デザインできるように準備します。
-
OnClick メソッドは、関連付けられた DetailsView のデザイン時ビューの領域がクリックされたときに呼び出されます。
-
OnSchemaRefreshed メソッドは、関連付けられた DetailsView のデータ ソースのスキーマが変更されたときに呼び出されます。
-
PreFilterProperties メソッドは、関連付けられた DetailsView に対して、プロパティの削除、追加、シャドウを行う場合に使用します。
DetailsView コントロールでは、デザイン時の編集可能領域がサポートされていないため、GetEditableDesignerRegionContent メソッドと SetEditableDesignerRegionContent メソッドは何の機能も提供しません。

DetailsViewDesigner クラスを拡張し、DetailsView コントロールから派生したコントロールの外観をデザイン時に変更するコード例を次に示します。
この例では、MyDetailsView コントロールを DetailsView から派生させています。MyDetailsView は、単に DetailsView コントロールのコピーです。また、この例では、DetailsViewDesigner から MyDetailsViewDesigner クラスを派生させ、MyDetailsViewDesigner の DesignerAttribute オブジェクトを MyDetailsView コントロールに配置しています。
The MyDetailsViewDesigner は、SampleRowCount プロパティをオーバーライドして、MyDetailsView のデザイン時ビューのページ行に 5 つのページ リンクが含まれることを指定します。また、PreFilterProperties メソッドをオーバーライドして、デザイン時に [Property] グリッドに NamingContainer プロパティを表示します。さらに、GetDesignTimeHtml メソッドをオーバーライドして、Caption プロパティが指定されている場合は、デザイン時の MyDetailsView グリッドの新しい先頭行としてこのプロパティを挿入します。MyDetailsView の BorderStyle プロパティの値が NotSet または None の場合、GetDesignTimeHtml は、コントロールの周囲に青い点線の境界線を描画して、コントロールの範囲をわかりやすくします。
Imports System 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 MyDetailsView is a copy of the DetailsView. <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermission(SecurityAction.InheritanceDemand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ <Designer(GetType(Examples.VB.WebControls.Design.MyDetailsViewDesigner))> _ Public Class MyDetailsView Inherits DetailsView End Class ' MyVBDetailsView ' Override members of the DetailsViewDesigner. <ReflectionPermission(SecurityAction.Demand, Flags:=ReflectionPermissionFlag.MemberAccess)> _ Public Class MyDetailsViewDesigner Inherits DetailsViewDesigner ' Determines the number of page links in the pager row ' when viewed in the designer. Protected Overrides ReadOnly Property SampleRowCount() As Integer Get ' Render five page links in the pager row. Return 5 End Get End Property ' SampleRowCount ' Shadow the control properties with design-time properties. Protected Overrides Sub PreFilterProperties( _ ByVal properties As IDictionary) ' Call the base method first. MyBase.PreFilterProperties(properties) ' Make the NamingContainer 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 ' Generate the design-time markup. Private Const capTag As String = "caption" Private Const trOpen As String = "tr><td colspan=2 align=center" Private Const trClose As String = "td></tr" Public Overrides Function GetDesignTimeHtml() As String ' Make the full extent of the control more visible in the designer. ' If the border style is None or NotSet, change the border to ' a wide, blue, dashed line. Include the caption within the border. Dim myDV As MyDetailsView = CType(Component, MyDetailsView) Dim markup As String = Nothing Dim charX As Integer ' Check if the border style should be changed. If (myDV.BorderStyle = BorderStyle.NotSet Or _ myDV.BorderStyle = BorderStyle.None) Then Dim oldBorderStyle As BorderStyle = myDV.BorderStyle Dim oldBorderWidth As Unit = myDV.BorderWidth Dim oldBorderColor As Color = myDV.BorderColor ' Set design-time properties and catch any exceptions. Try myDV.BorderStyle = BorderStyle.Dashed myDV.BorderWidth = Unit.Pixel(3) myDV.BorderColor = Color.Blue ' Call the base method to generate the markup. markup = MyBase.GetDesignTimeHtml() Catch ex As Exception markup = GetErrorDesignTimeHtml(ex) Finally ' Restore the properties to their original settings. myDV.BorderStyle = oldBorderStyle myDV.BorderWidth = oldBorderWidth myDV.BorderColor = oldBorderColor End Try Else ' Call the base method to generate the markup. markup = MyBase.GetDesignTimeHtml() End If ' Look for a <caption> tag. charX = markup.IndexOf(capTag) If charX > 0 Then ' Replace the first caption with ' "tr><td colspan=2 align=center". markup = markup.Remove(charX, _ capTag.Length).Insert(charX, trOpen) ' Replace the second caption with "td></tr". charX = markup.IndexOf(capTag, charX) If charX > 0 Then markup = markup.Remove(charX, _ capTag.Length).Insert(charX, trClose) End If End If Return markup End Function ' GetDesignTimeHtml End Class ' MyDetailsViewDesigner End Namespace ' Examples.VB.WebControls.Design
using System; 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 MyDetailsView is a copy of the DetailsView. [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [Designer(typeof(Examples.CS.WebControls.Design.MyDetailsViewDesigner))] public class MyDetailsView : DetailsView { } // MyDetailsView // Override members of the DetailsViewDesigner. [ReflectionPermission(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)] public class MyDetailsViewDesigner : DetailsViewDesigner { // Determines the number of page links in the pager row // when viewed in the designer. protected override int SampleRowCount { get { // Render five page links in the pager row. return 5; } } // SampleRowCount // Shadow the control properties with design-time properties. protected override void PreFilterProperties(IDictionary properties) { // Call the base method first. base.PreFilterProperties(properties); // Make the NamingContainer visible in the Properties grid. PropertyDescriptor selectProp = (PropertyDescriptor)properties["NamingContainer"]; properties["NamingContainer"] = TypeDescriptor.CreateProperty(selectProp.ComponentType, selectProp, BrowsableAttribute.Yes); } // PreFilterProperties // Generate the design-time markup. const string capTag = "caption"; const string trOpen = "tr><td colspan=2 align=center"; const string trClose = "td></tr"; public override string GetDesignTimeHtml() { // Make the full extent of the control more visible in the designer. // If the border style is None or NotSet, change the border to // a wide, blue, dashed line. Include the caption within the border. MyDetailsView myDV = (MyDetailsView)Component; string markup = null; int charX; // Check if the border style should be changed. if (myDV.BorderStyle == BorderStyle.NotSet || myDV.BorderStyle == BorderStyle.None) { BorderStyle oldBorderStyle = myDV.BorderStyle; Unit oldBorderWidth = myDV.BorderWidth; Color oldBorderColor = myDV.BorderColor; // Set design-time properties and catch any exceptions. try { myDV.BorderStyle = BorderStyle.Dashed; myDV.BorderWidth = Unit.Pixel(3); myDV.BorderColor = Color.Blue; // Call the base method to generate the markup. markup = base.GetDesignTimeHtml(); } catch (Exception ex) { markup = GetErrorDesignTimeHtml(ex); } finally { // Restore the properties to their original settings. myDV.BorderStyle = oldBorderStyle; myDV.BorderWidth = oldBorderWidth; myDV.BorderColor = oldBorderColor; } } else // Call the base method to generate the markup. markup = base.GetDesignTimeHtml(); // Look for a <caption> tag. if ((charX = markup.IndexOf(capTag)) > 0) { // Replace the first caption with // "tr><td colspan=2 align=center". markup = markup.Remove(charX, capTag.Length).Insert(charX, trOpen); // Replace the second caption with "td></tr". if ((charX = markup.IndexOf(capTag, charX)) > 0) markup = markup.Remove(charX, capTag.Length).Insert(charX, trClose); } return markup; } // GetDesignTimeHtml } // MyDetailsViewDesigner } // 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.DataBoundControlDesigner
System.Web.UI.Design.WebControls.DetailsViewDesigner


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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