liveBook · Manning

Column definition

As explained in .NET MAUI in Action

A column definition is a Grid specification that determines the sizing behavior of one column.

A column definition tells a .NET MAUI Grid how to size one column. Each definition supplies a Width value; together, the definitions establish the horizontal structure that controls use. Define columns before placing views so the Grid has predictable positions for controls such as buttons and labels. section 5.1.2

Add definitions either as nested XAML elements or inline on the Grid. Both approaches create the same layout, but inline ColumnDefinitions is shorter when the layout is straightforward. For a two-column Grid with equal columns, use two asterisks: each * receives an equal share of the available width. section 5.1.2

<Grid RowDefinitions="*,*"
      ColumnDefinitions="*,*">
</Grid>

Use the inline form to declare equal rows and columns directly on a Grid. section 5.1.2

Choose a Width value based on the behavior the interface needs:

  • Use * for proportional sizing. Equal * values divide available width equally; weighted values such as 3*, 2*, and 1* divide it into relative shares rather than fixed measurements. section 5.1.2 section 5.1.3
  • Use a numeric value for absolute sizing in DIUs. Four 100-width columns keep calculator buttons at a fixed width rather than allowing them to stretch with the window. section 5.1.3
  • Combine proportional and absolute definitions when different areas have different needs. A layout can reserve fixed button columns while another dimension takes remaining space with *. section 5.1.3

Proportional columns adapt to the available Grid width, which is useful for filling space, but they can distort a control’s appearance when a phone changes orientation or a desktop window is stretched. Fixed 100-DIU columns produce consistently sized calculator buttons across desktop and mobile, though the Grid may need alignment such as HorizontalOptions="Center" to control its placement. section 5.1.3 section 5.1.3

Build a calculator button grid

Start with four equal columns for a simple calculator: ColumnDefinitions="*,*,*,*". Place each button with Grid.Row and Grid.Column, remembering that columns begin at 0 from the left. If a display should cover the full button area, put it in column 0 and set Grid.ColumnSpan="4". When testing reveals horizontally stretched buttons, change the column definitions to "100,100,100,100" and keep the Grid centered. This fixes the button widths while leaving a star-sized screen row to use remaining height. section 5.1.2 section 5.1.2 section 5.1.3

ColumnSpacing adds a gap between columns in DIUs; without it, Grid columns have no space between them by default. Spacing changes separation between columns, whereas column definitions decide their widths. section 5.1.2

How .NET MAUI in Action covers it

How deep it goes
Explains inline and nested declarations plus proportional and absolute Width values, without describing lower-level layout internals.
Examples
Uses MauiCalc’s equal columns, weighted proportions, four fixed 100-DIU button columns, and a spanning display label.
What it assumes
Starts from a blank .NET MAUI app and teaches Grid declarations and zero-based column placement from scratch.
What you can do after
Apply it via .NET MAUI XAML to choose equal, weighted, or fixed Grid column widths for a responsive layout.
How it connects
Connects Grid, RowDefinition, Grid.Row, Grid.Column, Grid.ColumnSpan, ColumnSpacing, and HorizontalOptions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.