Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » WPF References » Use Expander and its ExpandDirection property in WPF using VB.NET

Use Expander and its ExpandDirection property in WPF using VB.NET

In this article we demonstrate on what is Expander and its ExpandDirection property.

Author Rank :
Page Views : 1340
Downloads : 4
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
Expander.zip
 
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


Introduction

In this article I am going to explain about the Expander control and its ExpandDirection property in WPF. The Expander control is like a GroupBox but with the additional features to collapse and expand its content. Exapnder is a Nifty control that will allow you to show and hide the controls you placed on it. We can place the Expander anywhere on our page and embed any content inside the DropDown area. The Expander control is derived from HeaderedContentControl so it has a header property to set the HeaderContent, and a Content property for the expandable content. You can see the Expander control in below image.

expender1.gif

How to set the Direction of the Expanded Content Area of Expander

The ExpandDirection Property gets or sets the Direction in which the content would Expand. We can set the direction of the Expanded content area of the Expander in one of the four Direction Down, Up, Left, Right by this property of the Expander. The Default value of the ExpandDirection Property is ExpandDirection.Down

Other Properties of Expander

  • IsExpanded:- The Default value of the IsExpanded Property is False. If the content window is Expanded the value of the property is true;otherwise False.

  • Header:- Header property of the Expander control gets the content of the Header Part.

  • Name:- This property gets the Name of the Expander control.

  • Height:- This property specifies the Height of the Object in Pixel.

  • IsEnabled:- This property specifies whether a control can accept user input or not.

You can see the Properties of Expander control in below Image.

expender3.gif

Getting Started

We are discussing as an example that how to use Expander control and its ExpandDirection property in WPF.

When we Drag the controls and sets all the properties our window will look like below.

expander2.gif

This is my XAML code

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="278" Width="353" Background
="Black" >
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="190"/>
            <ColumnDefinition Width="140"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>
<
StackPanel Grid.Column="0" Grid.Row="0" >
            <Expander Name="myFirstExpander" Background="SkyBlue"
HorizontalAlignment="Left" Header="My First Expander"
ExpandDirection="Down" IsExpanded="True" Width="139" Height="71">
                <TextBlock TextWrapping="Wrap">
                        Expander Example
               
</TextBlock>
           
</Expander>
        </StackPanel>
        <StackPanel Grid.Column="1" Grid.Row="0" >
            <TextBlock Margin="0, 10, 3, 3" FontSize="12" TextWrapping="Wrap" Foreground="White" Height="70"
Width="131" >
Check to change the ExpandDirection property on My First Expander
           
</TextBlock>
            <StackPanel >
                <RadioButton Name="MyExpandDown" Margin="0,10,0,10"
IsChecked="True"
Checked="ChangeExpandDirection"
GroupName="ExpandDirectionProperty" Foreground="White" Height="20" Width="124">                    
                    Expand Down
               
</RadioButton>
                <RadioButton Name="MyExpandUp" Margin="0,0,0,10"
Checked="ChangeExpandDirection"
GroupName="ExpandDirectionProperty" Foreground="White" Height="18" Width="121">
                    Expand Up
               
</RadioButton>
                <RadioButton Name="MyExpandLeft" Margin="0,0,0,10"
Checked="ChangeExpandDirection"
GroupName="ExpandDirectionProperty" Foreground="White" Height="19" Width="120">
                    Expand Left
               
</RadioButton>
                <RadioButton Name="MyExpandRight" Margin="0,0,0,10"
Checked="ChangeExpandDirection"
GroupName="ExpandDirectionProperty" Foreground="White" Height="20" Width="119">
                    Expand Right
               
</RadioButton>
            </StackPanel>
        </StackPanel>
</
Grid>
</
Window>

The NameSpaces which I have used are shown Below.

Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Media
Imports System.Windows.Navigation
Imports System.Windows.Shapes

This is my xaml.vb code

   
Private Sub ChangeExpandDirection(sender As Object, e As RoutedEventArgs)
        If CType(MyExpandDown.IsChecked, [Boolean]) Then
            myFirstExpander.ExpandDirection = ExpandDirection.Down
        ElseIf CType(MyExpandUp.IsChecked, [Boolean]) Then
            myFirstExpander.ExpandDirection = ExpandDirection.Up
        ElseIf CType(MyExpandLeft.IsChecked, [Boolean]) Then
            myFirstExpander.ExpandDirection = ExpandDirection.Left
        ElseIf CType(MyExpandRight.IsChecked, [Boolean]) Then
            myFirstExpander.ExpandDirection = ExpandDirection.Right
        End If
        myFirstExpander.IsExpanded = True
    End
Sub

When we Run the application the window will look like this.

expander4.gif

When we select the Expand Down Radio Button. The Window will look like Below.

expender4.gif

When we select the Expand Up Radio Button. The Window will look like Below.

expander5.gif

Like Above we can also select the Expand Left and Expand Right Radio Button to see the Changes.

Summary

In this article you learned about Expander control and its ExpandDirection property.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Shalini Juneja
Shalini juneja is working as a Software Trainnee .she has completed her Master degree in Computer application.she prefers to work in database and asp.net platform.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
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.
Dynamic PDF
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.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.