SIGN UP MEMBER LOGIN:    
ARTICLE

Expander Control in WPF

Posted by Syed Shakeer Articles | WPF with C# January 27, 2011
The Expander control is like a GroupBox but with the additional feature to collapse and expand its content.
Reader Level:

The Expander control is like a GroupBox but with the additional feature to collapse and expand its content. It derives from HeaderedContentControl so it has a Header property to set the header content, and a Content property for the expandable content.

It has a IsExpanded property to get and set if the expander is in expanded or collapsed state.

In collapsed state the expander takes only the space needed by the header. In expanded state it takes the size of header and content together.

Creating Expander Control .Xaml

Expander can be created by using Expander Element.

<Expander Header="Click here to see Image" Width="250" Foreground="Blue" >            

</Expander>

Header Property: Header Property is used for setting the content or text of a Expander Element.

<Expander Header="Expander Header Text">            

</Expander>

<Window x:Class="ExpanderWPF.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>
        <StackPanel Background="AntiqueWhite">
            <Expander Header="Click here to see Image" Width="250" Foreground="Blue" >             
                   
<Image Source="G:\ImageName.jpg"  Width="200"/>                              
            </Expander>
        </StackPanel>
    </Grid>
</
Window>

1.gif

By default the Expander Bullet button FlowDirection is LeftToRight.You can set the Expander Bullet direction to Right by setting FlowDirection Property to RightToLeft.

  <Expander Header="Click here to see Image" FlowDirection="RightToLeft" >                 
  </Expander>

Below is the Image of FlowDirection="RightToLeft"

2.gif


Below is the Image When you click the Expander control.

3.gif

Setting ScrollBar in Expander Control

You can set the ScrollBar in Expander Control by using ScrollBarViewr Element as follows

  <Expander Header="Click here to see Image" Width="250" Foreground="Blue" >                 

   
<ScrollViewer Height="150">
        <Image Source="G:\ImageName.jpg" Width="200"/>

    </ScrollViewer>               

 
</Expander>

Below is the Image of Expander with ScrollViewer

4.gif

Thanks for reading my article!

Shakeer
 

Login to add your contents and source code to this article
share this article :
post comment
 

Hi Syed, U did a gr8 job... I hope u ll give me a some more detail abt expander... How do I bind a expander value from database ????

Posted by Amrith Dhev May 17, 2011
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor