Home > DeveloperSection > Articles > TextBox Control in Windows 7 Phone Development

TextBox Control in Windows 7 Phone Development

Posted by  Arun Singh
on    April-13-2012 16:06 PM

Windows Phone Windows Phone 
0 Comment(s)
 2484  View(s)
Rate this:

TextBox Control in Windows 7 Phone Development

With the TextBox control, the user can enter text in an application. Typically, a TextBox control is used to display, or accept as input, a single line of text. You can use the Multiline and ScrollBars properties to enable multiple lines of text to be displayed or entered. This article is going to explain how to use TextBox control in windows 7 phone development.

Getting started:

1.       Open Visual Studio

2.       Create new Silverlight Windows 7 Phone Development Project

3.       Enter your project Name

4.       Click on button ‘Ok’

TextBox Control in Windows 7 Phone Development

Now drag and drop Textbox control form toolbox into MainPage.xaml design page; after doing this set proper layout of textbox control.

TextBox Control in Windows 7 Phone Development

Now write down the following line of code to build this layout;

Code of ‘MainPage.xaml’ file:

<!--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 Application  " Style="{StaticResource PhoneTextNormalStyle}"/>

            <TextBlock x:Name="PageTitle" Text="Textbox Demo" 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">

            <TextBlock Height="42" HorizontalAlignment="Left" Margin="30,6,0,0" Name="lblEmpDetails" Text="Employee Details" VerticalAlignment="Top" Width="366" DataContext="{Binding}" FontSize="32" />

            <TextBlock Height="50" HorizontalAlignment="Left" Margin="30,75,0,0" Name="lblName" Text="Emp Name" VerticalAlignment="Top" Width="165" FontSize="28" />

            <TextBox Height="72" HorizontalAlignment="Left" Margin="191,63,0,475" Name="txtName" Text="" VerticalAlignment="Center" Width="230" />

            <TextBlock Height="60" HorizontalAlignment="Left" Margin="35,163,0,0" Name="lblAddress" Text="Address" VerticalAlignment="Top" Width="118" FontSize="28" />

            <TextBox Height="72" HorizontalAlignment="Left" Margin="192,150,0,0" Name="txtAddress" Text="" VerticalAlignment="Top" Width="230" />

            <TextBlock Height="44" HorizontalAlignment="Left" Margin="36,247,0,0" Name="lblMobNo" Text="Mobile No." VerticalAlignment="Top" Width="144" FontSize="28" />

            <TextBox Height="72" HorizontalAlignment="Left" Margin="192,235,0,0" Name="txtMobNo" Text="" VerticalAlignment="Top" Width="229" />

            <Button Content="Submit" Height="72" HorizontalAlignment="Left" Margin="176,344,0,0" Name="btnSubmit" VerticalAlignment="Top" Width="160" Click="btnSubmit_Click" />





Code of MainPage.xaml.cs file:

using System.Windows;

using Microsoft.Phone.Controls;


namespace textBoxDemo


    public partial class MainPage : PhoneApplicationPage


        // Constructor

        public MainPage()





        private void btnSubmit_Click(objectsender, RoutedEventArgse)


            if (txtName.Text.Equals(string.Empty) || txtAddress.Text.Equals(string.Empty) ||txtMobNo.Text.Equals(string.Empty))

                MessageBox.Show("Please fill all enteries");


            MessageBox.Show("Data Successfull Submitted");







Now execute your program; following output will be appearing.

TextBox Control in Windows 7 Phone Development

Now fill all appropriate information in textfields and click on button ‘Submit’.

TextBox Control in Windows 7 Phone Development

This is the complete description about Textbox control in windows 7 phone development. I hope you will enjoy it.

Recent Activities

ben reitman Created New Discussion How To Change The Text Of The Td Using Jquery.?   a minute ago

Kamlakar Singh added new Blog Convert Text Document to PDF File   6 days ago

Kamlakar Singh added new Article Introduction to Backbone.js   6 days ago

Kamlakar Singh added new Question Explain the AdRotator Control.   7 days ago

Don't want to miss updates? Please click the below button!