Expander Class
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace: http://schemas.microsoft.com/winfx/2006/xaml/presentation
[LocalizabilityAttribute(LocalizationCategory::None, Readability=Readability::Unreadable)] public ref class Expander : public HeaderedContentControl
/** @attribute LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable) */ public class Expander extends HeaderedContentControl
LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable) public class Expander extends HeaderedContentControl
<Expander> Content </Expander>
Content Model: Expander is a HeaderedContentControl and has two content properties: Header and Content. For information about how to set these properties, see Headered Content Control Content Model.
The following illustration shows an Expander control.
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.
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 | This example shows how to create an Expander control. An Expander control enables users to view a header that expands to display more content or collapses to save space. |
| 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.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
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.