Reader Level:

Working With ListBox in Windows Store App

By Arjun Panwar on Feb 16, 2012
In this article I will discuss how to work with a ListBox in a Windows Store App.


In this article we define a ListBox, like ItemTemplates, ItemPanels and Binding. Here we can customize the layout and behavior of existing controls without the control exposes. Making a ListBox into a horizontal one can easily be done by changing the Itemspanel property. When we create a StackPanel with horizontal orientation, we get a horizontal ListBox.

in this section we will discuss how to define the ListBox in a Metro Style Application and later we will bind it through XAML code which is simple and easy to learn. First of all we will see how to start to build the Metro Style Application. For building that type of application you have to install the Windows 8 operating system and then install Visual Studio 2011. Let us see the steps given below of how to start building your application.

Step 1 : First of all you have to create a new Metro Style Application; let us see the description with images of how you will create it.

  • Open Visual Studio 2011

  • File->New Project

  • Select Metro Style Application in C# language

  • Click OK


Step 2: In the Solution Explorer we have to see the Mainpage.XAML file and open this file.


Step 3 : The XAML code looks like this. I have added a ItemContainerStyle, ListBox and a bit of padding.

Code :

<UserControl x:Class="Application13.MainPage"
d:DesignHeight="768" d:DesignWidth="1366">
<Grid x:Name="LayoutRoot" Background="Sienna">
<ListBox Height="96" HorizontalAlignment="Left" Margin="10,10,0,0" Name="listbox2" VerticalAlignment="Top" Width="470">
<StackPanel Orientation="Vertical" />                                    
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="30 0 30 0 " />
<ListBoxItem Content="Vertical Item 1" Background="AliceBlue" />
<ListBoxItem Content="Vertical Item 2" Background="SeaGreen" />
<ListBoxItem Content="Vertical Item 3" Background="BlanchedAlmond" />
<ListBoxItem Content="Vertical Item 4" Background="Chocolate"/>
<ListBoxItem Content="Vertical Item 5" Background="CornflowerBlue"/>

Step 4 : After running this application the output will look like as below:


In the blue print we have to select this item.


Here, we have to select  these items in horizontal form.


Arjun Panwar
Arjun Panwar

Arjun Panwar is a software developer working on Windows 8 platform and metro style apps.



JetBrains ReSharper Ultimate
.NET code analysis, refactorings, navigation, unit testing, code coverage and profiling in Visual Studio, a bonus for C++ devs, bundled at 50% off.

Trending up