---
title: "Button Control in Windows Phone 7 Development"  
description: "This article is going to explain how to use button control in windows 7 phone application using c# code.  Let’s see a brief demonstration on it."  
author: "Anonymous User"  
published: 2012-04-10  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/915/button-control-in-windows-phone-7-development  
category: "windows phone"  
tags: ["windows phone"]  
reading_time: 2 minutes  

---

# Button Control in Windows Phone 7 Development

This article is going to explain how to use [button control](https://www.mindstick.com/articles/290/button-control-in-vb-dot-net) in windows 7 phone [application using c#](https://www.mindstick.com/forum/160510/how-to-fetch-data-from-the-database-in-the-dot-net-console-application-using-c-sharp) code. Let’s see a brief demonstration on it.\

1. Open [visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) and go to **File -> New -> Project**.

2. Select [Silverlight](https://www.mindstick.com/blog/54/silverlight-in-asp-dot-net) for Windows Phone option

3. Enter the project name and choose the saving [location](https://www.mindstick.com/news/2574/twitter-conveniently-reveals-a-location-sharing-policy-amid-elonjet-controversy)

4. Click on button **‘Ok’**

![Button Control in Windows Phone 7 Development](https://www.mindstick.com/mindstickarticle/16bf42e6-f8a7-49b9-8496-16d34a327e2a/images/93f659a4-751b-4784-a180-99b3ed485d22.png)

Now click on Toolbox option which is at left corner; drag and drop button control into ‘MainPage.xaml’ user interface.

![Button Control in Windows Phone 7 Development](https://www.mindstick.com/mindstickarticle/16bf42e6-f8a7-49b9-8496-16d34a327e2a/images/d4a85210-6989-404e-915a-217ce38fc852.png)

Now change the title of page according to your [convenience](https://www.mindstick.com/forum/33530/convenience-vs-init-method-memory-usage) and write the [button click](https://www.mindstick.com/forum/568/check-condion-before-post-page-on-button-click-in-jquery-or-javascript) event code in **‘MainPage.xaml.cs’**

![Button Control in Windows Phone 7 Development](https://www.mindstick.com/mindstickarticle/16bf42e6-f8a7-49b9-8496-16d34a327e2a/images/ff854b66-2541-4c21-a58d-64ee51e15810.png)

##### Code of ‘MainPage.xaml’:

```
<!--LayoutRoot is the root grid where all page content is placed-->    <Grid x:Name="LayoutRoot" Background="Transparent">        <Grid.RowDefinitions>            <RowDefinition Height="Auto"/>            <RowDefinition Height="*"/>        </Grid.RowDefinitions>         <!--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="Home" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>        </StackPanel>         <!--ContentPanel - place additional content here-->        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">            <Button Content="Click Me!" Height="72" HorizontalAlignment="Left" Margin="142,118,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />        </Grid>    </Grid>
```

\

##### Code ‘MainPage.xaml.cs’:

```
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 testPhoneApp{    public partial class MainPage : PhoneApplicationPage    {        // Constructor        public MainPage()        {            InitializeComponent();        }         private void button1_Click(objectsender, RoutedEventArgse)        {            MessageBox.Show("Hello Click Me", "Clicked Event",MessageBoxButton.OK);        }          }} 
```

\

Press ctrl+F5 to run your application and after that following output will be appearing.

![Button Control in Windows Phone 7 Development](https://www.mindstick.com/mindstickarticle/16bf42e6-f8a7-49b9-8496-16d34a327e2a/images/fe401223-34c9-453a-b35a-7f40b23b7d8e.png)

Now click on button **‘Click Me!’**

![Button Control in Windows Phone 7 Development](https://www.mindstick.com/mindstickarticle/16bf42e6-f8a7-49b9-8496-16d34a327e2a/images/d8f1313e-2805-4487-8f79-3fa7b077e978.png)

This is the complete description on Button control in Windows 7 Phone Development. I hope you will be enjoying this article.

---

Original Source: https://www.mindstick.com/articles/915/button-control-in-windows-phone-7-development

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
