#492 – Layout Can Change at Runtime

One benefit of flow-based layout, as opposed to coordinate-based layout, is that elements in the user interface will size to fit their content.  The GUI designer does not have to explicitly set the size and location of each child element.

The layout containers in WPF don’t just position their child elements at design-time, but will re-measure and arrange their child elements when certain properties of the child elements change.  For example, if the Content property of a Label control changes, the parent container will update its layout based on the new text.

In the example below, when the Label containing the movie title changes, the buttons to its right shift.

        <Label Content="Have you seen this movie?" Margin="3"/>
        <StackPanel Orientation="Horizontal">
            <Label Content="{Binding NextMovieTitle}" Margin="3"/>
            <Button Content="Seen It" Margin="3"/>
            <Button Content="NOT Seen It" Margin="3"/>
        <Button Content="Next Movie" HorizontalAlignment="Center" Margin="3"


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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: