Print Pyramid in Windows Store App

In this article I explain how to print pyramids in a Windows Store app. Generally printing pyramids is very common in the C language. But later printing a pyramid has become common in C#. But to print a pyramid in a Windows Form is not an easy job. So here I will  describe how to a print pyramid in a Windows Store app.

To Print the pyramid in Windows Store app do the following steps.

Step 1

First of all you have to create a New Window Store Application.

  • Open Visual Studio 2012
  • "File" -> "New" -> "Project..."
  • Choose Template: "Visual C#" -> "Window Store app"
  • "Blank App (XAML)", then rename the application


Step 2

Write the following simple XAML code for "Mainpage.Xaml" (that is available in Solution Explorer):










    <Grid Background="Blue">


            <ColumnDefinition Width="661*"/>

            <ColumnDefinition Width="705*"/>



            <RowDefinition Height="143*"/>

            <RowDefinition Height="38*"/>

            <RowDefinition Height="43*"/>

            <RowDefinition Height="300*"/>

            <RowDefinition Height="0*"/>

            <RowDefinition Height="39*"/>

            <RowDefinition Height="205*"/>


        <TextBlock Text="Print Pyramid" FontSize="25" FontWeight="ExtraBold" Grid.ColumnSpan="2" Grid.Row="1" TextAlignment="Center" Foreground="Red" ></TextBlock>

        <TextBlock Text="Enter Line no:" FontSize="25" FontWeight="ExtraBold" Grid.Column="0" Grid.Row="2" Foreground="Red" TextAlignment="Right"> </TextBlock>

        <TextBox x:Name="textbox1" Grid.Column="1" Grid.Row="2" Width="150" Height="35" VerticalAlignment="Top" HorizontalAlignment="Left" />

        <TextBlock x:Name="text1" FontSize="25" FontWeight="ExtraBold" Grid.Column="1" Grid.Row="3" Foreground="Red" TextWrapping="Wrap" Width="466" HorizontalAlignment="Left" />

        <Button x:Name="Button1" Content="Click" Click="Button1_Click" Foreground="Red" Background="Yellow" Grid.Column="1" Grid.Row="1"  Height="44" Width="141" VerticalAlignment="Top" Grid.RowSpan="2"  HorizontalAlignment="Center"   Margin="148,37,416,0"   />





Step 3

Now write the following C# code for the button within "Mainpage.Xaml.cs":

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using Windows.Foundation;

using Windows.Foundation.Collections;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Controls.Primitives;

using Windows.UI.Xaml.Data;

using Windows.UI.Xaml.Input;

using Windows.UI.Xaml.Media;

using Windows.UI.Xaml.Navigation;


namespace Pyramid_app


    public sealed partial class MainPage : Page


        public MainPage()




        protected override void OnNavigatedTo(NavigationEventArgs e)



        private void Button1_Click(object sender, RoutedEventArgs e)


            text1.Text = "";

            int range = Convert.ToInt32(textbox1.Text);          

for (int j = 1; j <= i; j++)
                    text1.Text +=


                text1.Text += Environment.NewLine;


Step 4

Run your App.