Parameter.OnParameterChanged 方法

定義

呼叫OnParametersChanged(EventArgs)包含該ParameterCollection物件的集合的方法Parameter

protected:
 void OnParameterChanged();
protected void OnParameterChanged();
member this.OnParameterChanged : unit -> unit
Protected Sub OnParameterChanged ()

範例

以下程式碼範例示範如何在參數狀態變更時呼叫 OnParameterChanged 該方法以引發 ParametersChanged 事件。 這個程式碼範例是為類別概述提供 Parameter 的完整範例的一部分。

// The Value property is a type safe convenience property
// used when the StaticParameter represents string data.
// It gets the string value of the DataValue property, and
// sets the DataValue property directly.
public string Value {
  get {
    object o = DataValue;
    if (o == null || !(o is string))
      return String.Empty;
    return (string)o;
  }
  set {
    DataValue = value;
    OnParameterChanged();
  }
}
' The Value property is a type safe convenience property
' used when the StaticParameter represents string data.
' It gets the string value of the DataValue property, and
' sets the DataValue property directly.
Public Property Value() As String
   Get
      Dim o As Object = DataValue
      If o Is Nothing OrElse Not TypeOf o Is String Then
         Return String.Empty
      End If
      Return CStr(o)
   End Get
   Set
      DataValue = value
      OnParameterChanged()
   End Set
End Property

備註

如果 Parameter 物件不被 ParameterCollection 集合包含,呼叫該 OnParameterChanged 方法不會產生影響。 若物件 ParameterParameterCollection 集合包含, OnParameterChanged 則會 ParameterCollection.ParametersChanged 觸發集合的事件。

若集合 ParameterCollection 被資料來源控制所包含, ParameterCollection.ParametersChanged 事件會觸發資料來源控制 DataSourceChanged 的事件,導致任何資料綁定控制項重新綁定。

發起事件會透過代理呼叫事件處理者。 欲了解更多資訊,請參閱 處理與提升事件

OnParameterChanged 方法也允許衍生類別在不附加代理的情況下處理事件。 這是在衍生類別中處理事件的首選技術。

給繼承者的注意事項

在導出類別中覆寫 OnParameterChanged() 時,務必呼叫基底類別的方法 OnParameterChanged() ,讓註冊代理接收事件。

適用於

另請參閱