Skip navigation

I bumped into a relatively old posting on Rob Relyea’s blog that talks about the differences between using XAML for your UI and using imperative code (C#, VB). The entry was in response to one in Charles Petzold’s blog where he asks if this disparity was purposeful or accidental.
I would just have to ask Charles if he has looked at the code generated by the Winforms Designer lately?
Let’s say I create a form with a DataGridView holding three columns. Here is the generated code for that very simple UI

private void InitializeComponent()
  this.dataGridView1 = new System.Windows.Forms.DataGridView();
  this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
  // dataGridView1
  this.dataGridView1.AllowUserToAddRows = false;
  this.dataGridView1.AllowUserToDeleteRows = false;
  this.dataGridView1.ColumnHeadersHeightSizeMode =  System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  this.dataGridView1.Columns.AddRange(new  System.Windows.Forms.DataGridViewColumn[] {
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(0, 0);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
this.dataGridView1.Size = new System.Drawing.Size(292, 266);
this.dataGridView1.TabIndex = 0;
// Column1
this.Column1.HeaderText = "Column1";
this.Column1.Name = "Column1";
this.Column1.ReadOnly = true;
// Column2
this.Column2.HeaderText = "Column2";
this.Column2.Name = "Column2";
this.Column2.ReadOnly = true;
// Column3
this.Column3.HeaderText = "Column3";
this.Column3.Name = "Column3";
this.Column3.ReadOnly = true;
// Form1
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";

So you see imperative UI code was always verbose. It was just hidden from us by the designer. I guess a case to consider is allowing Cider to generate imperative code as well as XAML…but why?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: