WPF Expander control in VB.NET

In this article we will learn how to use Expander control in WPF.
  • 2168

In this article we will learn how to use Expander control in WPF.

Expander control

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

Properties - This control has the following property.

e1.gif

Figure 1.

Here are few snapshots of this control.

e2.gif

Figure 2.

XAML code

The following XAML code creates the Expander control at design.

<Window x:Class="MainWindow"

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

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

    Title="MainWindow" Height="350" Width="525">

    <Grid Height="320">

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="374*" />

            <ColumnDefinition Width="129*" />

        </Grid.ColumnDefinitions>

        <Expander Width="352" HorizontalContentAlignment="Stretch" Margin="0,0,22,187"ExpandDirection="Down" 
FlowDirection
="LeftToRight" BorderThickness="4"HorizontalAlignment="Right" Background="Brown" Name="Expander1">

            <Expander.Header>

                <BulletDecorator>

                    <BulletDecorator.Bullet>

                        <Image Width="10" Source="images\icon.jpg"/>

                    </BulletDecorator.Bullet>

                    <TextBlock Margin="20,0,0,0" Width="87">My Expander</TextBlock>

                </BulletDecorator>

            </Expander.Header>

            <Expander.Content>

                <ScrollViewer Height="50">

                    <TextBlock TextWrapping="Wrap">

                Lorem ipsum dolor sit amet, consectetur adipisicing elit,

                sed do eiusmod tempor incididunt ut labore et dolore magna

                aliqua. Ut enim ad minim veniam, quis nostrud exercitation

                ullamco laboris nisi ut aliquip ex ea commodo consequat.

                Duis aute irure dolor in reprehenderit in voluptate velit

                esse cillum dolore eu fugiat nulla pariatur. Excepteur sint

                occaecat cupidatat non proident, sunt in culpa qui officia

                deserunt mollit anim id est laborum.

                    </TextBlock>

                </ScrollViewer>

            </Expander.Content>

        </Expander>

         </Grid>

</Window>

Now run the application and test it.

e3.gif

Figure 3.

Now click on the expander control. This looks like this.

e4.gif

Figure 4.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.