Export (0) Print
Expand All
1 out of 3 rated this helpful - Rate this topic

Expander Class

Updated: February 2009

Represents the control that displays a header that has a collapsible window that displays content.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
public class Expander : HeaderedContentControl
<Expander>
  Content
</Expander>

Content Model: Expander is a HeaderedContentControl. Its content property is Content and its header property is Header. For more information on the content model for Expander, see Controls Content Model Overview.

The following illustration shows an Expander control.

Expander example

If the content of the expanded window is too large for the window, you can wrap the content of the Expander in a ScrollViewer control to provide scrollable content. Scrolling capability is not automatically provided by the Expander control.

For an Expander to work correctly, do not specify a Height on the Expander control when the ExpandDirection property is set to Down or Up. Similarly, do not specify a Width on the Expander control when the ExpandDirection property is set to Left or Right. When you set a size on the Expander control in the direction that the expanded content is displayed, the area that is defined by the size parameter is displayed with a border around it. This area displays even when the window is collapsed. To set the size of the expanded window, set size dimensions on the content of the Expander control or the ScrollViewer that encloses the content.

When an Expander control is the last element in a DockPanel, the Expander is sized to fill the remaining area of the DockPanel. To prevent this, set the LastChildFill property on the DockPanel to false, or make sure that the Expander is not the last element in a DockPanel.

The alignment of Expander content can be defined by setting the HorizontalContentAlignment and VerticalContentAlignment properties on the control. These properties are applied to the header and to the contents of the expanded window.

Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Themes.

The following example shows how to create a simple Expander control.

<Expander Name="myExpander" Background="Tan" 
          HorizontalAlignment="Left" Header="My Expander" 
          ExpandDirection="Down" IsExpanded="True" Width="100">
  <TextBlock TextWrapping="Wrap">
    Lorem ipsum dolor sit amet, consectetur
    adipisicing elit, sed do eiusmod tempor incididunt ut
    labore et dolore magna aliqua
  </TextBlock>
</Expander>

More Code

How to: Create an Expander with a ScrollViewer This example shows how to create an Expander control that contains complex content, such as an image and text. The example also encloses the content of the Expander in a ScrollViewer control.
How to: Create a Control That Has an Access Key and Text Wrapping This example shows how to create a control that has an access key and supports text wrapping. The example uses a Label control to illustrate these concepts.
System.Object
  System.Windows.Threading.DispatcherObject
    System.Windows.DependencyObject
      System.Windows.Media.Visual
        System.Windows.UIElement
          System.Windows.FrameworkElement
            System.Windows.Controls.Control
              System.Windows.Controls.ContentControl
                System.Windows.Controls.HeaderedContentControl
                  System.Windows.Controls.Expander
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Date

History

Reason

February 2009

Described how default styles change dependency properties.

Customer feedback.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.