#1,179 – Alignment and Margin Properties for a Custom FrameworkElement

When you create a custom control that derives from FrameworkElement, your control has access to all standard FrameworkElement behavior.  This includes the use of the Margin property, as well as the HorizontalAlignment and VerticalAlignment properties.

Below, we use margin and alignment in positioning a custom framework element within a Grid.

    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        
        <loc:MyFrameworkElement HorizontalAlignment="Center"
                                VerticalAlignment="Top"
                                Height="40" Width="100"/>
        <loc:MyFrameworkElement Grid.Row="1" Margin="20,10"/>
    </Grid>

(Showing grid lines for clarity).

1179-001

Advertisements