Vitalij
Vitalij

Reputation: 4625

Weird padding behaviour

In my application a try to position 8 small squares around one big one. See image below.

alt text

<UserControl
    <UserControl.Resources>
    <Style x:Key="ResizerStyle" TargetType="UserControl">
    <Setter Property="Width" Value="{Binding Padding.Top, ElementName=border, Mode=Default}"/>
    <Setter Property="Height" Value="{Binding Padding.Top, ElementName=border, Mode=Default}"/>
    </Style>
    <Thickness x:Key="ScalersSize">8</Thickness>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Border x:Name="border" BorderThickness="1" Panel.ZIndex="-1000" Padding="{DynamicResource ScalersSize}" Background="#00000000">
            <Rectangle Fill="#FFC00000"/>
        </Border>
        <local:Scaler VerticalAlignment="Top" Cursor="SizeNS" HorizontalAlignment="Center" Style="{StaticResource ResizerStyle}"/>
        <local:Scaler VerticalAlignment="Top" Cursor="SizeNESW" HorizontalAlignment="Right" Style="{StaticResource ResizerStyle}"/>
        <local:Scaler VerticalAlignment="Top" HorizontalAlignment="Left" Cursor="SizeNWSE" Style="{StaticResource ResizerStyle}"/>
        <local:Scaler VerticalAlignment="Bottom" Cursor="SizeNS" Style="{StaticResource ResizerStyle}"/>
        <local:Scaler VerticalAlignment="Bottom" Cursor="SizeNWSE" Style="{StaticResource ResizerStyle}" HorizontalAlignment="Right"/>
        <local:Scaler VerticalAlignment="Bottom" Cursor="SizeNESW" Style="{StaticResource ResizerStyle}" HorizontalAlignment="Left"/>
        <local:Scaler HorizontalAlignment="Right" VerticalAlignment="Center"  Cursor="SizeWE" Style="{StaticResource ResizerStyle}"/>
        <local:Scaler HorizontalAlignment="Left" VerticalAlignment="Center"  Cursor="SizeWE" Style="{StaticResource ResizerStyle}"/>
    </Grid>
</UserControl>

And the following renders red 62x62 square. But as far as I know 80 - 8 * 2 = 64. So why it is rendered it as 62 by 62 square?

Upvotes: 0

Views: 88

Answers (1)

John Bowen
John Bowen

Reputation: 24453

I don't know where you're getting the 80 from since it's not anywhere in your XAML but I assume that's supposed to be the size of the outer UserControl. In your calculation you missed one part: the border itself. You have the BorderThickness set to 1 which means there is a 1 unit area on all sides being held for the border line but not being shown because there isn't a BorderBrush set. So the actual size is 80 - (8 * 2) - (1 * 2) = 62

Upvotes: 1

Related Questions