using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApp53 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); MainWindow_Loaded(); } Grid gd { get; set; } private void MainWindow_Loaded() { gd = new Grid(); gd.ShowGridLines = true; for (int i = 0; i < 12; i++) { gd.RowDefinitions.Add(new RowDefinition()); } for (int j = 0; j < 12; j++) { gd.ColumnDefinitions.Add(new ColumnDefinition()); } var pis = typeof(Colors).GetProperties(); int idx = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { Border bd = new Border(); var cr = (Color)(pis[(idx++) % (pis.Count())].GetValue(typeof(Colors))); bd.Background = new SolidColorBrush(cr); Grid.SetRow(bd, i); Grid.SetColumn(bd, j); gd.Children.Add(bd); } } this.Content = gd; } } }
标签:Winodws,Windows,System,int,Colors,gd,using,WPF,MainWindow From: https://www.cnblogs.com/Fred1987/p/18592555