ControlDesigner.SetEditableDesignerRegionContent 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定設計時控制項可編輯區域的內容。
public:
virtual void SetEditableDesignerRegionContent(System::Web::UI::Design::EditableDesignerRegion ^ region, System::String ^ content);
public virtual void SetEditableDesignerRegionContent(System.Web.UI.Design.EditableDesignerRegion region, string content);
abstract member SetEditableDesignerRegionContent : System.Web.UI.Design.EditableDesignerRegion * string -> unit
override this.SetEditableDesignerRegionContent : System.Web.UI.Design.EditableDesignerRegion * string -> unit
Public Overridable Sub SetEditableDesignerRegionContent (region As EditableDesignerRegion, content As String)
參數
- region
- EditableDesignerRegion
控制項內可編輯的設計區域。
- content
- String
可編輯設計區域要指派的內容。
範例
以下程式碼範例說明如何取得設計主機的參考,然後利用該參考建立 ControlParser 一個物件 content ,該物件會變成介面的實例 ITemplate ,並將實例指派 ITemplate 到適當的視圖。
// Create a template from the content string and
// put it in the selected view.
public override void SetEditableDesignerRegionContent(EditableDesignerRegion region, string content)
{
if (content == null)
return;
// Get a reference to the designer host
IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
if (host != null)
{
// Create a template from the content string
ITemplate template = ControlParser.ParseTemplate(host, content);
// Determine which region should get the template
// Either 'Content0' or 'Content1'
if (region.Name.EndsWith("0"))
myControl.View1 = template;
else if (region.Name.EndsWith("1"))
myControl.View2 = template;
}
}
' Create a template from the content string and put it
' in the selected view. Called by the designer host?
Public Overrides Sub SetEditableDesignerRegionContent(ByVal region As EditableDesignerRegion, ByVal content As String)
If IsNothing(content) Then
Return
End If
' Get a reference to the designer host
Dim host As IDesignerHost = CType(Component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)
If Not IsNothing(host) Then
' Create a template from the content string
Dim template As ITemplate = ControlParser.ParseTemplate(host, content)
' Determine which region should get the template
If region.Name.EndsWith("0") Then
myControl.View1 = template
ElseIf region.Name.EndsWith("1") Then
myControl.View2 = template
End If
End If
End Sub
備註
從該 ControlDesigner 類別衍生的類別可支援設計表面的區域編輯,並覆寫 SetEditableDesignerRegionContent 設定指定區域內容的方法。