差一行代码就差这么多,真的很神奇...... using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace Cloud.DockAroundTheBlock { class DockAroundTheBlock : Window { [STAThread] public static void Main() { Application app = new Application(); app.Run(new DockAroundTheBlock()); } public DockAroundTheBlock() { Title = "Dock Around the Block"; DockPanel dock = new DockPanel(); Content = dock; for (int i = 0; i < 17; i++) { Button btn = new Button(); btn.Content = "Button No. " + (i + 1); dock.Children.Add(btn); btn.SetValue(DockPanel.DockProperty, (Dock)(i % 4)); // 加了這行變很怪 //btn.HorizontalAlignment = HorizontalAlignment.Center; } // 加這個才會讓最後一個按鈕(NO.17)也被dock dock.LastChildFill = false; } } }