UIElementCollection.Add(UIElement) Metoda

Definicja

Dodaje określony element do elementu UIElementCollection.

public:
 virtual int Add(System::Windows::UIElement ^ element);
public virtual int Add (System.Windows.UIElement element);
abstract member Add : System.Windows.UIElement -> int
override this.Add : System.Windows.UIElement -> int
Public Overridable Function Add (element As UIElement) As Integer

Parametry

element
UIElement

Element do dodania UIElement .

Zwraca

Int32

Pozycja indeksu dodanego elementu.

Przykłady

W poniższym przykładzie Add użyto metody , aby dodać zawartość podrzędną do elementu nadrzędnego StackPanel. W tym celu należy użyć Children właściwości , która jest typu UIElementCollection.

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

Dotyczy

Zobacz też