web-dev-qa-db-ja.com

プログラムで新しい要素をDockPanelにドッキングする方法

どのようにプログラムでユーザーコントロールに基づいて要素を作成し、それをDockPanelに追加しますか?

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

here および here も参照してください。

65
Lars Truijens
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);

3
Dani
var uc = new UserControl1();
uc.SetValue(DockPanel.DockProperty, Dock.Left);
myDockPanel.Children.Add(uc);
2
Walter Fuchs