UIElementCollection.Add(UIElement) Método

Definição

Adiciona o elemento especificado na 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

Parâmetros

element
UIElement

O UIElement a ser adicionado.

Retornos

Int32

A posição no índice do elemento adicionado.

Exemplos

O exemplo a seguir usa o Add método para adicionar conteúdo filho a um pai StackPanel. Você faz isso usando a Children propriedade, que é do tipo UIElementCollection.

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

Aplica-se a

Confira também