This post shows how to add string objects to a ListBox Control in Windows Phone.

Make sure to choose a C# template for the project.

This is the layout .

ListBox Windows Phone

This is the complete Layout
Just change the class name in the root of the layout to yours.

    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY LISTBOX APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="ListBox Application" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox Height="383" HorizontalAlignment="Left" Margin="3,7,0,0" Name="listBox1" VerticalAlignment="Top" Width="448" />
            <Button Content="Add to ListBox" Height="72" HorizontalAlignment="Left" Margin="86,499,0,0" Name="button1" VerticalAlignment="Top" Width="250" Click="button1_Click" />
            <TextBlock Height="30" HorizontalAlignment="Left" Margin="12,414,0,0" Name="textBlock1" Text="Type something to add to the ListBox" VerticalAlignment="Top" Width="443" />
            <TextBox Height="72" HorizontalAlignment="Left" Margin="3,436,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="460" />

Now we will look at the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace ListBoxExample
    public partial class MainPage : PhoneApplicationPage
        // Constructor
        public MainPage()
            listBox1.Items.Add("ListBox Demo From Coderzheaven"); 

        private void button1_Click(object sender, RoutedEventArgs e)

Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.