#761 – How FlowDirection Affects HorizontalContentAlignment

The FlowDirection property, which can be LeftToRight or RightToLeft, indicates how elements within a control should be layed out.

FlowDirection of RightToLeft reverse the meaning of all HorizontalContentAlignment values.  The example below shows the effect of different combinations of HorizontalContentAlignment and FlowDirection for some Label controls.

    <Grid ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Label Content="HorizontalContentAlignment / FlowDirection Values" Grid.Row="0" Grid.ColumnSpan="2"
               HorizontalAlignment="Center"/>

        <Label Content="Left / LeftToRight" Grid.Row="1" Grid.Column="0"
               HorizontalAlignment="Stretch" HorizontalContentAlignment="Left"
               Background="Bisque"/>
        <Label Content="Left / RightToLeft" Grid.Row="1" Grid.Column="1"
               HorizontalAlignment="Stretch" HorizontalContentAlignment="Left"
               FlowDirection="RightToLeft"
               Background="Bisque"/>

        <Label Content="Right / LeftToRight" Grid.Row="2" Grid.Column="0"
               HorizontalAlignment="Stretch" HorizontalContentAlignment="Right"
               Background="Bisque"/>
        <Label Content="Right / RightToLeft" Grid.Row="2" Grid.Column="1"
               HorizontalAlignment="Stretch" HorizontalContentAlignment="Right"
               FlowDirection="RightToLeft"
               Background="Bisque"/>
    </Grid>

761-001

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a comment