Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can percentage values be used in XAML?

Tags:

xaml

Grid ColumnDefinitions and RowDefinitions allow for proportional units (in addition to fixed pixels and Auto).

Here are 2 examples:

<Grid.ColumnDefinitions>
  <ColumnDefinition Width="Auto" />
  <ColumnDefinition Width="20" />
  <ColumnDefinition Width="*" />
  <ColumnDefinition Width="*"/>
  <ColumnDefinition Width="*"/>
  <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

The first column will be as large as necessary to fit all content in the column. The next column is 20 device-independant pixels wide. The remaining Width of the grid will be divided equally among the remaining columns. (100% / 4 = 25% in each)

<Grid.ColumnDefinitions>
  <ColumnDefinition Width="*" />
  <ColumnDefinition Width="4*"/>
  <ColumnDefinition Width="4*"/>
  <ColumnDefinition Width="*"/> 
</Grid.ColumnDefinitions>

This code would divide 4 columns into 10%, 40%, 40%, and 10% of the total Grid Width.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!