开发者

How programmatically dock new element to DockPanel

How programmatically create an element based on UserControl and dock it to the DockPanel? 开发者_运维技巧


var myControl = new MyUserControl();
DockPanel.SetDock(myControl, Dock.Left);
myDockPanel.Children.Add(myControl);

Also see here and here.


Button TopRect = new Button();

TopRect.Background = new SolidColorBrush(Colors.LightGreen);

TopRect.Height = 50;

TopRect.Content = "Top";

// Dock button to top

DockPanel.SetDock(TopRect, Dock.Top);

// Add docked button to DockPanel

dcPanel.Children.Add(TopRect);

Example


var uc = new UserControl1();
uc.SetValue(DockPanel.DockProperty, Dock.Left);
myDockPanel.Children.Add(uc);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜