How to create Expander in WPF

An Expander control provides a way to provide content in an expandable area that resembles a window and includes a header.

The following XAML code shows how to create an Expander control in WPF.

<Window x:Class="ExpanderControlSample.Window1"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Window1" Height="300" Width="300">

    <Grid>

        <Expander Name="ExpanderControl" Background="LavenderBlush"

          HorizontalAlignment="Left" Header="Click to Expand"

          ExpandDirection="Down" IsExpanded="False" Width="200"

                  FontSize="20" FontWeight="Bold" Foreground="Green">

            <TextBlock TextWrapping="Wrap" FontSize="14" FontWeight="Light" Foreground="Black">

                This is an Expander control. Within this control, all contents will be wrapped.

                At run-time, you may expand or collapse this control. Type more text here to be typed.

                Jump around and hype.

            </TextBlock>

        </Expander>

 

    </Grid>

</Window>