This topic has not yet been rated - Rate this topic

Expander Class

[Note: This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)
[TemplateVisualStateAttribute(Name = "ExpandDown", GroupName = "ExpandDirectionStates")]
[TemplateVisualStateAttribute(Name = "Expanded", GroupName = "ExpansionStates")]
[TemplateVisualStateAttribute(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "MouseOver", GroupName = "CommonStates")]
[TemplatePartAttribute(Name = "ExpanderButton", Type = typeof(ToggleButton))]
[TemplateVisualStateAttribute(Name = "Disabled", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Focused", GroupName = "FocusStates")]
[TemplateVisualStateAttribute(Name = "Unfocused", GroupName = "FocusStates")]
[TemplateVisualStateAttribute(Name = "Pressed", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Collapsed", GroupName = "ExpansionStates")]
[TemplateVisualStateAttribute(Name = "ExpandUp", GroupName = "ExpandDirectionStates")]
[TemplateVisualStateAttribute(Name = "ExpandLeft", GroupName = "ExpandDirectionStates")]
[TemplateVisualStateAttribute(Name = "ExpandRight", GroupName = "ExpandDirectionStates")]
public class Expander : HeaderedContentControl
<controls:Expander .../>
-or-
<expander>
  singleObject
</expander>
-or-
<expander>
  <expander.Header>
    singleHeader
  </expander.Header>
  singleObject
</expander>


XAML Values

controls:

A prefix that is defined to map the XML namespace for the System.Windows.Controls assembly and the System.Windows.Controls CLR namespace.

expander

An Expander object element, or an object element for a class that derives from Expander. Either case requires a prefix.

singleObject

A single object element that declares the content.

singleHeader

A single object element that declares the header.

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.

Content Model: Expander is a HeaderedContentControl. Its content property is Content and its header property is Header.

The following illustration shows an Expander control.

Expander Control

Expander Control

XAML Usage for Classes Derived from Expander

If you define a class that derives from Expander, the class can be used as an object element in XAML, and all of the inherited properties and events that show a XAML usage in the reference for the Expander members can have the same XAML usage for the derived class. However, the object element itself must have a different prefix mapping than the controls: mapping shown in the usages, because the derived class comes from an assembly and namespace that you create and define.

The following example displays an Expander control.

<!--An Expander control with the ExpandDirection property set to Down-->
<controls:Expander Name="MyExpander1" Background="Aquamarine" HorizontalAlignment="Left" Header="Down Expander" ExpandDirection="Down" IsExpanded="True" Width="150">
    <TextBlock TextWrapping="Wrap">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
    </TextBlock>
</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.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)