EditorPart.ApplyChanges メソッド

定義

EditorPart コントロールの値を、関連付けられている WebPart コントロールの対応するプロパティに保存します。

public:
 abstract bool ApplyChanges();
public abstract bool ApplyChanges ();
abstract member ApplyChanges : unit -> bool
Public MustOverride Function ApplyChanges () As Boolean

戻り値

EditorPart コントロールから WebPart コントロールへの値の保存アクションに成功した場合は true。それ以外の場合 (エラーが発生した場合) は false

次のコード例では、 メソッドをカスタム EditorPart コントロールに実装ApplyChangesする方法を示します。 この例を実行するために必要な完全なコードについては、クラスの概要の「例」セクションを EditorPart 参照してください。

コード例の最初の部分では、 という名前TextDisplayEditorPartのカスタム EditorPart クラスでの メソッドのApplyChanges実装を示します。 このメソッドは、 プロパティを使用して、関連付けられた TextDisplayWebPart コントロールへの参照を WebPartToEdit 取得します。 次に、 プロパティの値を TextDisplayWebPart.FontStyle 更新します。

public override bool ApplyChanges()
{
  TextDisplayWebPart part = 
    (TextDisplayWebPart)WebPartToEdit;
  // Update the custom WebPart control with the font style.
  part.FontStyle = PartContentFontStyle.SelectedValue;

  return true;
}
Public Overrides Function ApplyChanges() As Boolean
  Dim part As TextDisplayWebPart = CType(WebPartToEdit, _
                                         TextDisplayWebPart)
  ' Update the custom WebPart control with the font style.
  part.FontStyle = PartContentFontStyle.SelectedValue

  Return True

End Function

コード例の 2 番目の部分では、 メソッドの実装CreateEditorPartsで、TextDisplayWebPart関連付けられたコントロールのコレクション (この場合、コレクション内に という名前TextDisplayEditorPartのコントロールが 1 つだけEditorPart存在する) を、関連付けられたWebPartEditorPartコントロール がどのように作成するかを示します。 このメソッドは、コントロールが編集モードになったとき TextDisplayWebPart に実行されます。

public override EditorPartCollection CreateEditorParts()
{
  ArrayList editorArray = new ArrayList();
  TextDisplayEditorPart edPart = new TextDisplayEditorPart();
  edPart.ID = this.ID + "_editorPart1";
  editorArray.Add(edPart);
  EditorPartCollection editorParts = 
    new EditorPartCollection(editorArray);
  return editorParts;
}

public override object WebBrowsableObject
{
  get { return this; }
}
Public Overrides Function CreateEditorParts() _
                            As EditorPartCollection
  Dim editorArray As New ArrayList()
  Dim edPart as New TextDisplayEditorPart()
  edPart.ID = Me.ID & "_editorPart1"
  editorArray.Add(edPart)
  Dim editorParts As New EditorPartCollection(editorArray)
  Return editorParts

End Function

Public Overrides ReadOnly Property WebBrowsableObject() _
                                    As Object
  Get
    Return Me
  End Get
End Property

注釈

メソッドは ApplyChanges 、コントロールの重要な EditorPart メソッドです。 これは クラスの EditorPart 抽象メソッドとして定義されており、継承されたコントロールによって実装される必要があります。 メソッドの目的は、ユーザーがコントロールに入力した値を EditorPart 、 プロパティで参照されているコントロール内の WebPart 対応するプロパティに WebPartToEdit 保存することです。

このメソッドは ApplyChanges 、ユーザーが編集ユーザー インターフェイス (UI) で OK または apply 動詞を表すボタンをクリックすると呼び出されます。

注意 (実装者)

クラスから派生するクラスは、 メソッドを EditorPart 実装する ApplyChanges() 必要があります。 実装されたメソッドは、 プロパティを使用して関連付けられたコントロールへの参照を WebPartToEdit 取得し、そのコントロールのプロパティをコントロールの現在の値で EditorPart 更新します。

適用対象

こちらもご覧ください