UIElementCollection.Clear 方法

定義

將所有項目從 UIElementCollection 移除。

public:
 virtual void Clear();
public virtual void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Overridable Sub Clear ()

實作

範例

下列範例會 Clear 使用 方法來清除父 StackPanel 代 的子內容。 您可以使用 屬性來執行此 Children 動作,其類型 UIElementCollection 為 。

void AddButton(object sender, MouseButtonEventArgs e)
{
    sp1.Children.Clear();
    btn = new Button();
    btn.Content = "New Button";
    sp1.Children.Add(btn);
}

適用於

另請參閱