Here's some sample code:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
string xaml = @"<StackPanel xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""><TextBox Width=""150"" Height=""25"" /></StackPanel>";
var ui = System.Windows.Markup.XamlReader.Parse(xaml) as FrameworkElement;
var textBox = VisualTreeHelper.GetChild(ui, 0) as TextBox;
textBox.Text = DateTime.Now.ToLongTimeString();
mainGrid.Children.Add(ui);
}
mainGrid
is a
Grid
control. The dynamically loaded content is added to this
Grid
.