WPF: How to display content in an Expander


The following XAML demonstrates how to use two Expander objects.The first Expander expands horizontally and uses an image in its header. The second Expander contains a set of System.Windows.Controls.Button objects and expands downward.
 
XAML CODE:

<
Window x:Class="Expander.MainWindow"
xmlns
=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Title="MainWindow" Height="200" Width="300">
   <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility
="Auto">
      <StackPanel HorizontalAlignment
="Left">
         <Expander ExpandDirection="Right" IsExpanded
="True">
            
<Expander.Header
>
               <Image Source
="Apress.gif"/>   
            </Expander.Header
>  
   
            
<TextBlock TextWrapping="Wrap" MaxWidth
="200">
               Windows Presentation Foundation (WPF) is the presentation
               subsystem feature of the .NET Framework 4.0,that provide good 
               design and advance controls. Silverlight is the Subset of WPF.
               
Through WPF we can create Windows and WebBrowser Application.
            </TextBlock>
         </Expander
>
         <Expander Header
="Buttons">
            <StackPanel
>
               <StackPanel Orientation
="Horizontal">
                  <Button Content="Button 1" Margin
="2"/>
                  <Button Content="Button 2" Margin
="2"/>
                  <Button Content="Button 3" Margin
="2"/>
                  <Button Content="Button 4" Margin
="2"/>
                  
<Button Content="Button 5" Margin
="2"/>
               </StackPanel
>
               <StackPanel HorizontalAlignment
="Left">
                  <Button Content="Button A" Margin
="2" />
                  <Button Content="Button B" Margin
="2" />
                  <Button Content="Button C" Margin
="2" />
                  <Button Content="Button D" Margin
="2" />
                  <Button Content="Button E" Margin
="2" />
               </StackPanel
>
            </StackPanel
>   
         </Expander
>
      </StackPanel
>
   </ScrollViewer
>
</
Window>

Ebook Download
View all
Learn
View all
F11Research & Development, LLC