WPF - Percentage Margin

I just started using WPF. Since then I get a head from the styling system. I come from CSS background and I would like to set margin as a percentage.

    <Style TargetType="TextBlock" x:Key="workflowNameTextBlock">            
        <Setter Property="Margin" Value="50"/>            
    </Style>

The current value is set in pixels, but I would like to set it to%, i.e. 50%.

How can I achieve this?

thank

+5
source share
2 answers

Here you implement 20% of the left and right margins in WPF:

<Grid>
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="2*"/>
      <ColumnDefinition Width="6*"/>
      <ColumnDefinition Width="2*"/>
   </Grid.ColumnDefinitions>
   <TextBlock Grid.Column="1" Text="Hello, world."/>
</Grid>

This may seem ridiculously detailed if what you are trying to do is to redesign a simple CSS layout in WPF, but that is because implementing simple CSS layouts is not really the WPF problem space created around.

+14
source

Margin Grid.

Grid 3 3 . / .

+3

All Articles