How to: Add an Element Dynamically
This example shows how to add a Button element to a StackPanel by using the Add method of the Children property.
The following Extensible Application Markup Language (XAML) example creates a TabControl. When a user clicks the Add Control tab, a MouseLeftButtonDown event handler, AddButton, which is written in code, clears any existing controls and adds a new button.