Rowdefinition Height = "*" and columndefinition width = "*" in C #

Source: Internet
Author: User

The data type of columndefinition. width is gridlength, so you can write it:

Column1.width = new gridlength (1, gridunittype. Star); // column1 is an instance.

If columndefinition width = "Auto", you can write it

Column1.width = gridlength. Auto;

Do not confuse here. gridlength. Auto is a structure, while new gridlength (1, gridunittype. Star) is a class.

 

Below is a complete layout code, all completed using C # code (Exercise)

Public partial class mainwindow: Window
{
Public mainwindow ()
{
Initializecomponent ();

// Display grid
Grid1.showgridlines = true;

// Line
Rowdefinition row1 = new rowdefinition ();
Rowdefinition row2 = new rowdefinition ();

// Column
Columndefinition column1 = new columndefinition ();
Columndefinition column2 = new columndefinition ();

// Use the * layout. When the value is 1, when the * value is 2, 2 * indicates that the width of the second column is twice the width of the first column.
Column1.width = new gridlength (1, gridunittype. Star );
Column2.width = new gridlength (2, gridunittype. Star );

Button button1 = new button ();
Button button2 = new button ();
Button button3 = new button ();
Button button4 = new button ();

// Add rows and columns to the grid panel
Grid1.rowdefinitions. Add (row1 );
Grid1.rowdefinitions. Add (row2 );

Grid1.columndefinitions. Add (column1 );
Grid1.columndefinitions. Add (column2 );

// Add the button to the grid panel
Grid1.children. Add (button1 );
Grid1.children. Add (button2 );
Grid1.children. Add (button3 );
Grid1.children. Add (button4 );

Button1.content = "1 ";
Button2.content = "2 ";
Button3.content = "3 ";
Button4.content = "4 ";

// Set the cell where each button is located
Grid. setrow (button1, 0 );
Grid. setcolumn (button1, 0 );

Grid. setrow (button2, 0 );
Grid. setcolumn (button2, 1 );

Grid. setrow (button3, 1 );
Grid. setcolumn (button3, 0 );

Grid. setrow (button4, 1 );
Grid. setcolumn (button4, 1 );

}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.