Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Margin as percentage in WPF's XAML

Tags:

wpf

xaml

I would like to make a UniformGrid take 70% of total window width and 80% of total window height. How achieve it?

<UniformGrid x:Name="Grid" Margin="20,0,0,0">

</UniformGrid>
like image 342
Yoda Avatar asked Jan 04 '14 22:01

Yoda


1 Answers

Like the other answer suggests, you first create a Grid like so:

<Grid>
  <Grid.RowDefinitions>
     <RowDefinition Height="8*" />
     <RowDefinition Height="2*" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
     <ColumnDefinition Width="7*" />
     <ColumnDefinition Width="3*" />
  </Grid.ColumnDefinitions>

  <UniformGrid x:Name="yourGrid">
  </UniformGrid>
</Grid>

Then you set your UniformGrid control as the child in the 0th row 0th column of the main grid. The x* notation means that you want x parts of the screen used in the row/column, so splitting rows at 8*/2* splits them at 80%/20% and splitting columns and 7*/3* splits them at 70%/30%. I hope that clears it up for you.

like image 81
Eugene Avatar answered Nov 12 '22 05:11

Eugene