How programmatically dock new element to DockPanel
var myControl = new MyUserControl();DockPanel.SetDock(myControl, Dock.Left);myDockPanel.Children.Add(myControl);
Button TopRect = new Button();TopRect.Background = new SolidColorBrush(Colors.LightGreen);TopRect.Height = 50;TopRect.Content = "Top";// Dock button to topDockPanel.SetDock(TopRect, Dock.Top);// Add docked button to DockPaneldcPanel.Children.Add(TopRect);
var uc = new UserControl1();uc.SetValue(DockPanel.DockProperty, Dock.Left);myDockPanel.Children.Add(uc);