Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the WPF star do (Width="100*")

Tags:

wpf

xaml

size

grid

What does exactly the star in size terms in WPF mean?

like image 947
Shimmy Weitzhandler Avatar asked Nov 20 '09 04:11

Shimmy Weitzhandler


People also ask

What does * mean in WPF?

In a WPF Grid, Width="*" or Height="*" means proportional sizing. For example: to give 30% to column 1 and 70% to column 2 - <ColumnDefinition Width="3*" /> <ColumnDefinition Width="7*" /> And likewise for rows - <RowDefinition Height="3*" /> <RowDefinition Height="7*" />

What is Grid view in WPF?

The GridView view mode displays a list of data items by binding data fields to columns and by displaying a column header to identify the field. The default GridView style implements buttons as column headers.

What is grid row in WPF?

A Grid Panel provides a flexible area which consists of rows and columns. In a Grid, child elements can be arranged in tabular form. Elements can be added to any specific row and column by using Grid.Row and Grid.Column properties. By default, a Grid panel is created with one row and one column.

What is Grid in XAML?

In XAML a Grid is made up of a series of rows and columns. By specifying the row and column of an element within a Grid, you can place and space other elements within a user interface. Rows and columns are defined with the RowDefinition and ColumnDefinition elements.


1 Answers

In a WPF Grid, Width="*" or Height="*" means proportional sizing.
For example: to give 30% to column 1 and 70% to column 2 -

<ColumnDefinition Width="3*" /> <ColumnDefinition Width="7*" /> 

enter image description here

And likewise for rows -

<RowDefinition Height="3*" /> <RowDefinition Height="7*" /> 

The numbers do not have to be integers.
If the Width for RowDefinition (Height for ColumnDefinition) is omitted, 1* is implied.
In this example, column 1 is 1.5 times wider than column 2 -

<ColumnDefinition Width="1.5*" /> <ColumnDefinition /> 

Column 1: 1.5*, Column 2 1* (implied)

You can mix auto-fit and fixed widths with * (proportional) widths; in that case the * columns are apportioned to the remainder after the auto-fit and fixed widths have been calculated -

<Grid.ColumnDefinitions>     <ColumnDefinition Width="Auto" />  <!-- Auto-fit to content, 'Hi' -->     <ColumnDefinition Width="50.5" />  <!-- Fixed width: 50.5 device units) -->     <ColumnDefinition Width="69*" />   <!-- Take 69% of remainder -->     <ColumnDefinition Width="31*"/>    <!-- Take 31% of remainder --> </Grid.ColumnDefinitions> <TextBlock Text="Hi" Grid.Column="0" /> 

enter image description here

like image 150
Edward Avatar answered Oct 08 '22 21:10

Edward