ExpanderView in Silverlight for Windows Phone Toolkit
(Vaishali Rawat -) |
hamishwillee
(Talk | contribs) m (Hamishwillee - Addition to article of: Category:Windows Phone 7.5) |
||
| (8 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
| − | [[Category:Windows Phone]] | + | [[Category:Windows Phone]][[Category:UI]][[Category:Code Examples]] |
| − | {{Abstract|This | + | {{Abstract|This code example explains how to use {{Icode|ExpanderView}} control from the [[Silverlight for Windows Phone Toolkit]].}} |
| − | + | {{SeeAlso| | |
| + | * [[Silverlight for Windows Phone Toolkit In Depth (EBook)]] | ||
| + | * [http://cespage.com/silverlight/wp7tut24.html Expander control tutorial] (CESPage.com) | ||
| + | * [http://www.windowsphonegeek.com/articles/Expand-and-Collapse-ExpanderView-inside-data-bound-ListBox-via-code Expand and Collapse ExpanderView inside data bound ListBox via code] (windowsphonegeek.com) | ||
| + | * Windows Phone Toolkit ExpanderView in depth (windowsphonegeek.com) | ||
| + | ** [http://www.windowsphonegeek.com/articles/Windows-Phone-Toolkit-ExpanderView-in-depth-Part1-key-concepts-and-API Part1: key concepts and API] | ||
| + | ** [http://windowsphonegeek.com/articles/Windows-Phone-Toolkit-ExpanderView-in-depth-Part2-Data-Binding Part2: Data Binding] | ||
| + | }} | ||
{{ArticleMetaData <!-- v1.2 --> | {{ArticleMetaData <!-- v1.2 --> | ||
| − | |sourcecode= <!-- Link to example source code e.g. | + | |sourcecode= [[Media:ExpanderControl.zip]] <!-- Link to example source code e.g. --> |
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
|devices= Tested with the Lumia 800 <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | |devices= Tested with the Lumia 800 <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| Line 9: | Line 16: | ||
|platform= Windows Phone 7.5 <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | |platform= Windows Phone 7.5 <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
|devicecompatability= All Windows Phones <!-- Compatible devices e.g.: All* (must have internal GPS) --> | |devicecompatability= All Windows Phones <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| − | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> |
| − | |signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | + | |signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> |
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| − | |keywords= [http://msdn.microsoft.com/en-us/library/system.windows.controls.expander.aspx Expander control] | + | |keywords= [http://msdn.microsoft.com/en-us/library/system.windows.controls.expander.aspx Expander control] |
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
|translated-by= <!-- [[User:XXXX]] --> | |translated-by= <!-- [[User:XXXX]] --> | ||
| − | |translated-from-title= <!-- Title only --> | + | |translated-from-title= <!-- Title only --> |
|translated-from-id= <!-- Id of translated revision --> | |translated-from-id= <!-- Id of translated revision --> | ||
| − | |review-by=<!-- After re-review: [[User:username]] --> | + | |review-by= <!-- After re-review: [[User:username]] --> |
|review-timestamp= <!-- After re-review: YYYYMMDD --> | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
|update-by= <!-- After significant update: [[User:username]]--> | |update-by= <!-- After significant update: [[User:username]]--> | ||
| Line 26: | Line 33: | ||
== Introduction == | == Introduction == | ||
| − | ExpanderView | + | {{Icode|ExpanderView}} comes with the [[Silverlight for Windows Phone Toolkit]]. It has a header which the user can toggle to expand/collapse additional content (this type of control is sometimes referred to as a collapsible panel or as an accordion control). |
| − | + | ||
| − | + | This article provides a brief overview of how to include and use the control in your projects. The example uses two {{Icode|ExpanderView}} components: the first displays a list of teams participating in a game, while the second allows you to select a specific game from a list. | |
| + | |||
<gallery widths=200px heights=350px> | <gallery widths=200px heights=350px> | ||
| − | File:Expander1.png| | + | File:Expander1.png|Example app with expanders "closed" |
| − | File:Expander2.png| | + | File:Expander2.png|"Teams" header expanded: view displays list of teams in cricket match |
| − | File:Expander3.png| | + | File:Expander3.png|"Choose Match" expanded: view displays list of matches (checkable) |
| − | File:Expander4.png| | + | File:Expander4.png|Example app with selected match |
</gallery> | </gallery> | ||
| − | == | + | == Adding the control to your project == |
| − | First create a Windows Phone application | + | First create a Windows Phone application: |
| − | + | ||
* Open Visual Studio and select '''Windows Phone Application''' from the installed templates | * Open Visual Studio and select '''Windows Phone Application''' from the installed templates | ||
* Select Windows Phone 7.1 as the Target Version. | * Select Windows Phone 7.1 as the Target Version. | ||
| Line 48: | Line 55: | ||
== Defining ExpanderView Control through XAML == | == Defining ExpanderView Control through XAML == | ||
| + | The XAML code below shows how we create a {{Icode|ExpanderView}} named "Header 1", comprising of 8 {{Icode|TextBlock}} items. | ||
<code xml> | <code xml> | ||
<toolkit:ExpanderView x:Name="Header1" Header="Teams " FontSize="40" Expanded="Header1_Expanded"/> | <toolkit:ExpanderView x:Name="Header1" Header="Teams " FontSize="40" Expanded="Header1_Expanded"/> | ||
| Line 63: | Line 71: | ||
</code> | </code> | ||
| − | + | == Defining ExpanderView Control using CSharp == | |
| − | + | The same control can be created in C# as shown below: | |
| − | + | * First we create an instance of {{Icode|ExpanderView}} (in this case called {{Icode|Header1}}): | |
| − | * | + | *: <code csharp> ExpanderView Header1 = new ExpanderView();</code> |
| − | * | + | * Then we set the header text, add the expander to a {{Icode|stackpanel}}, and set the content of the expander as a list. |
<code csharp> | <code csharp> | ||
| − | + | public MainPage() | |
| − | + | { | |
| − | + | InitializeComponent(); | |
| − | + | Header1.Header = "Expander Header"; | |
| − | + | stackpanel.Children.Add(Header1); | |
| − | + | this.Header1.ItemsSource = new List<string>() { "Afganistan", "Australia", "Bangladesh", | |
| − | + | "Ireland", "New Zealand", "South Africa", "Sri Lanka", "Zimbabwe" }; | |
| + | } | ||
</code> | </code> | ||
| − | ==Expanded and | + | ==Expanded and collapsed events== |
| − | ExpanderView has two key events | + | {{Icode|ExpanderView}} has two key events {{Icode|Expanded}} and {{Icode|Collapsed}} which are triggered when the state of {{Icode|ExpanderView}} is changed. |
| − | + | When the {{Icode|Header1}} {{Icode|ExpanderView}} is expanded its {{Icode|Expanded}} handler is called: | |
<code csharp> | <code csharp> | ||
| − | + | private void Header1_Expanded(object sender, RoutedEventArgs e) | |
| − | + | { | |
| − | + | // can define any specific action we want to take when the ExpanderView expands | |
| − | + | } | |
</code> | </code> | ||
| − | + | Similarly, when it is collapsed, the {{Icode|Collapsed}} handler is called: | |
<code csharp> | <code csharp> | ||
| − | + | private void Header1_Collapsed(object sender, RoutedEventArgs e) | |
| − | + | { | |
| − | + | // can define any specific action we want to take when the ExpanderView collapses | |
| − | + | } | |
</code> | </code> | ||
| − | {{Note|ExpanderView has IsNonExpandable property which makes the ExpanderView non expandable.}} | + | {{Note|{{Icode|ExpanderView}} has {{Icode|IsNonExpandable}} property which makes the {{Icode|ExpanderView}} non expandable. This is useful if the expander can only be used in certain circumstances - perhaps after its content is fully populated.}} |
== Downloads == | == Downloads == | ||
You can download sample project code from this file [[File:ExpanderControl.zip]]. | You can download sample project code from this file [[File:ExpanderControl.zip]]. | ||
| + | |||
| + | <!-- Translation --> [[zh-hans:Silverlight for Windows Phone Toolkit中的ExpanderView控件]][[Category:Windows Phone 7.5]] | ||
Latest revision as of 08:15, 30 November 2012
This code example explains how to use ExpanderView control from the Silverlight for Windows Phone Toolkit.
See Also
- Silverlight for Windows Phone Toolkit In Depth (EBook)
- Expander control tutorial (CESPage.com)
- Expand and Collapse ExpanderView inside data bound ListBox via code (windowsphonegeek.com)
- Windows Phone Toolkit ExpanderView in depth (windowsphonegeek.com)
Article Metadata
Code Example
Tested with
Compatibility
Article
Contents |
Introduction
ExpanderView comes with the Silverlight for Windows Phone Toolkit. It has a header which the user can toggle to expand/collapse additional content (this type of control is sometimes referred to as a collapsible panel or as an accordion control).
This article provides a brief overview of how to include and use the control in your projects. The example uses two ExpanderView components: the first displays a list of teams participating in a game, while the second allows you to select a specific game from a list.
Adding the control to your project
First create a Windows Phone application:
- Open Visual Studio and select Windows Phone Application from the installed templates
- Select Windows Phone 7.1 as the Target Version.
- Right-click on the “References” in the project and click “Add Reference…”.Browse the “Microsoft.Phone.Controls.Toolkit.dll” and add it to the project.
- Add namespace of Microsoft.Phone.Controls.Toolkit in MainPage.xaml.
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
Defining ExpanderView Control through XAML
The XAML code below shows how we create a ExpanderView named "Header 1", comprising of 8 TextBlock items.
<toolkit:ExpanderView x:Name="Header1" Header="Teams " FontSize="40" Expanded="Header1_Expanded"/>
<toolkit:ExpanderView.Items>
<TextBlock FontSize="20" Text="Afganistan"/>
<TextBlock FontSize="20" Text="Australia"/>
<TextBlock FontSize="20" Text="Bangladesh"/>
<TextBlock FontSize="20" Text="Ireland"/>
<TextBlock FontSize="20" Text="New Zealand"/>
<TextBlock FontSize="20" Text="South Africa"/>
<TextBlock FontSize="20" Text="Sri Lanka"/>
<TextBlock FontSize="20" Text="Zimbabwe"/>
</toolkit:ExpanderView.Items>
</toolkit:ExpanderView>
Defining ExpanderView Control using CSharp
The same control can be created in C# as shown below:
- First we create an instance of ExpanderView (in this case called Header1):
-
ExpanderView Header1 = new ExpanderView();
-
- Then we set the header text, add the expander to a stackpanel, and set the content of the expander as a list.
public MainPage()
{
InitializeComponent();
Header1.Header = "Expander Header";
stackpanel.Children.Add(Header1);
this.Header1.ItemsSource = new List<string>() { "Afganistan", "Australia", "Bangladesh",
"Ireland", "New Zealand", "South Africa", "Sri Lanka", "Zimbabwe" };
}
Expanded and collapsed events
ExpanderView has two key events Expanded and Collapsed which are triggered when the state of ExpanderView is changed.
When the Header1 ExpanderView is expanded its Expanded handler is called:
private void Header1_Expanded(object sender, RoutedEventArgs e)
{
// can define any specific action we want to take when the ExpanderView expands
}
Similarly, when it is collapsed, the Collapsed handler is called:
private void Header1_Collapsed(object sender, RoutedEventArgs e)
{
// can define any specific action we want to take when the ExpanderView collapses
}
Downloads
You can download sample project code from this file File:ExpanderControl.zip.

