[WPF] 神奇的DockPanel

差一行代码就差这么多,真的很神奇......

 

[WPF] 神奇的DockPanel_第1张图片

[WPF] 神奇的DockPanel_第2张图片

[WPF] 神奇的DockPanel_第3张图片

 

 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; } } } 

你可能感兴趣的:(application,Class,button,WPF)