Saturday, June 14, 2014

How to save session

If we want to restore state in the event the user closed the app, you can use the following code:
if(args.PreviousExecutionState == ApplicationExecutionState.Terminated
    || args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser)
{
try
{
awaitSuspensionManager.RestoreAsync();
    }


If the state was Terminated, then the app calls RestoreAsync and restores the app’s state.
if(args.PreviousExecutionState == ApplicationExecutionState.Terminated)
    {
try
{
awaitSuspensionManager.RestoreAsync();
        }
catch(SuspensionManagerException)
        {
 
}
    }

If we want to restore state in the event the user closed the app, you can use the following code:
if(args.PreviousExecutionState == ApplicationExecutionState.Terminated
    || args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser)
{
// Restore the saved session state only when appropriate
try
{
awaitSuspensionManager.RestoreAsync();
    }


CHAPTER 4 EX 04 My To Do

<Page
    x:Class="MyToDo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyToDo"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

   
       
            <Grid Background="#FFA800FF" Width="1600" Height="900" Tapped="Grid_Tapped_1">
                <Rectangle Fill="Black" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="1878"/>
                <TextBlock Margin="639,28,561,0" HorizontalAlignment="Center" Text="My To Do" VerticalAlignment="Top" Height="72" FontSize="48" Width="400"/>

                <Grid x:Name="grd" Margin="0,7,0,-7">
                    <TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="Task Description" VerticalAlignment="Top" Width="Auto" Margin="17,132,0,0" FontSize="36"/>

                    <TextBox x:Name="txtTaskDescription" HorizontalAlignment="Left" Margin="286,137,0,0" AcceptsReturn="True" Text="" VerticalAlignment="Top" Width="384" Height="109" GotFocus="txtTaskDescription_GotFocus"/>
                    <TextBlock HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Text="Task Category" VerticalAlignment="Top" Width="Auto" Margin="17,267,0,0" FontSize="36"/>
                    <ListView x:Name="lstViewTaskCategories" Foreground="White" FontSize="20"  HorizontalAlignment="Left" Height="100" Margin="289,276,0,0"  VerticalAlignment="Top" Width="384" BorderBrush="AliceBlue" BorderThickness="1">

                    </ListView>
                    <TextBlock x:Name="txtdesc" Visibility="Collapsed" HorizontalAlignment="Left" Height="Auto" TextWrapping="Wrap" Foreground="Red" Text="Please provide Task Description." VerticalAlignment="Top" Width="656" Margin="17,549,0,0" FontSize="36"/>
                    <TextBlock HorizontalAlignment="Left" Height="81" TextWrapping="Wrap" Text="To be Completed by" VerticalAlignment="Top" Width="257" Margin="17,397,0,0" FontSize="36"/>
                    <ComboBox x:Name="cboxYear" HorizontalAlignment="Left" Margin="289,427,0,0" VerticalAlignment="Top" Width="120"/>
                    <ComboBox x:Name="cboxMonth" HorizontalAlignment="Left" Margin="422,427,0,0" VerticalAlignment="Top" Width="120"/>
                    <ComboBox x:Name="cboxDay" HorizontalAlignment="Left" Margin="553,427,0,0" VerticalAlignment="Top" Width="120"/>
                    <GridView x:Name="grdToDos" SelectionChanged="grdToDos_SelectionChanged_1" HorizontalAlignment="Left" Margin="719,132,0,0" VerticalAlignment="Top" Width="825" Height="460" BorderThickness="2" />
                    
                </Grid>
                <AppBar x:Name="appbar" VerticalAlignment="Bottom">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Row="0" Grid.Column="0" x:Name="bttnAddToDo" Content="Add"  Click="bttnAddToDo_Click_1"></Button>
                        <Button Grid.Row="0" Grid.Column="1" x:Name="bttnRemoveToDo" Visibility="Collapsed"   Content="Remove" Click="bttnRemoveFromGrid_Click_1"></Button>
                    </Grid>
                </AppBar>



            </Grid>
      
</Page>



Cs File:


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;
using System.Collections.ObjectModel;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace MyToDo
{
    public class ToDos
    {
        public string TaskDescription { get; set; }
        public string TaskCategory { get; set; }
        public string TaskDeadLine { get; set; }
        public bool isCompleted { get; set; }
        public ToDos(string description, string category, string deadline, bool isCompleted = false)
        {
            TaskDescription = description;
            TaskCategory = category;
            TaskDeadLine = deadline;
            this.isCompleted = isCompleted;
        }
    }
    public sealed partial class MainPage : Page
    {


        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
       ObservaleCollection<ToDos> toDosCollection = new  ObservaleCollection<ToDos>
        
        public MainPage()
        {
            this.InitializeComponent();
            fillYear(2012, 2090);
            fillMonth();
            fillDays();
            cboxMonth.SelectionChanged += cboxMonth_SelectionChanged;
            cboxYear.SelectionChanged += cboxYear_SelectionChanged;
            lstViewTaskCategories.Items.Add("Personal");
            lstViewTaskCategories.Items.Add("Official");
            lstViewTaskCategories.SelectedIndex = 0;

        }

        void cboxYear_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            fillDays();
        }

        void cboxMonth_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            fillDays();
        }
        void fillDays()
        {
            cboxDay.Items.Clear();
            cboxDay.Items.Add("");
            try
            {
                int days = DateTime.DaysInMonth(Convert.ToInt32(cboxYear.SelectedValue), getMonth(cboxMonth.SelectedValue.ToString()));
                for (int i = 1; i <= days; i++)
                    cboxDay.Items.Add(i);
                cboxDay.SelectedIndex = 0;
            }
            catch (Exception ex)
            {


            }

        }
        int getMonth(string monthName)
        {
            switch (monthName)
            {
                case "January":
                    return 1;
                case "February":
                    return 2;
                case "March":
                    return 3;
                case "April":
                    return 4;
                case "May":
                    return 5;
                case "June":
                    return 6;
                case "July":
                    return 7;
                case "August":
                    return 8;
                case "September":
                    return 9;
                case "October":
                    return 10;
                case "November":
                    return 11;
                case "December":
                    return 12;
                default:
                    return -1;

            }
        }
        void fillMonth()
        {
            cboxMonth.Items.Add("");
            cboxMonth.Items.Add("January");
            cboxMonth.Items.Add("February");
            cboxMonth.Items.Add("March");
            cboxMonth.Items.Add("April");
            cboxMonth.Items.Add("May");
            cboxMonth.Items.Add("June");
            cboxMonth.Items.Add("July");
            cboxMonth.Items.Add("August");
            cboxMonth.Items.Add("September");
            cboxMonth.Items.Add("October");
            cboxMonth.Items.Add("November");
            cboxMonth.Items.Add("December");
            cboxMonth.SelectedIndex = 0;
        }
        void fillYear(int startYear, int endYear)
        {
            cboxYear.Items.Add("");
            for (int i = startYear; i <= endYear; i++)
                cboxYear.Items.Add(i);
            cboxYear.SelectedIndex = 0;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        private void bttnAddToDo_Click_1(object sender, RoutedEventArgs e)
        {
           txtdesc.Text = "Please provide complete information.";

            if (string.IsNullOrEmpty(txtTaskDescription.Text.Trim()) || cboxYear.SelectedIndex==0 || cboxMonth.SelectedIndex==0 || cboxDay.SelectedIndex==0)
            {
                txtdesc.Visibility = Windows.UI.Xaml.Visibility.Visible;
               
                return;
            }
            else
            {
                txtdesc.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                
                
                grdToDos.Items.Add(txtTaskDescription.Text);
                txtTaskDescription.Text = "";
                cboxDay.SelectedIndex = cboxMonth.SelectedIndex = cboxYear.SelectedIndex = 0;
                txtTaskDescription.Focus(Windows.UI.Xaml.FocusState.Programmatic);
            }

        }


        private void bttnRemoveFromGrid_Click_1(object sender, RoutedEventArgs e)
        {
           if(grdToDos.SelectedItams.Count > 0)
            {
               try
                {
                  if(toDosCollection.Count >1)
                   {
                     toDosCollection.Remove(grdToDos.SelectedItam as ToDos);
                     grdToDos.ItemsSource = toDosCollection;
                   }
                   else
                   {
                      toDosCollection.Clear();
                      gedToDos.ItemsSource = null;
                   }
                }
                catch (Exception)
                 {
                    
                 }
            }
        }


                    

        private void grdToDos_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            if (grdToDos.Items.Count > 0 && grdToDos.SelectedItems.Count > 0)
                bttnRemoveToDo.Visibility = Windows.UI.Xaml.Visibility.Visible;
            else
                bttnRemoveToDo.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }

        private void Grid_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            appbar.IsOpen = false;
        }

        private void txtTaskDescription_GotFocus(object sender, RoutedEventArgs e)
        {
            appbar.IsOpen = false;
        }
    }
}

Friday, June 13, 2014

CHAPTER 4 EX 02 Ryan Dessert App

Ex 2) Ryan a Windows Store app developer,needs to create a recipe app for deserts.The app is expected to display the images of the various desserts whose recipes are available,as shown in the following figur.
Whenever a user clicks the image of a desert,the app should navigate to a page containing the recipe for the sme.The expected interface of the recipe page is shown in the following figure.
In addition,each recipe page should allow the user to go back on the main page of the app.

Ans 2) main page xaml code

<Page
    x:Class="Deserts.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Deserts"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Transitions>

        <EntranceThemeTransition></EntranceThemeTransition>

    </Page.Transitions>
    <Page.Resources>
        <DataTemplate x:Key="imgSourceDataTemplate">
            <Image Source="{Binding imgURL}" Tag="{Binding imgURL}" Height="350" Width="350"  Stretch="Fill"></Image>

        </DataTemplate>
    </Page.Resources>
    <Grid Background="#ff96d823">
        <GridView x:Name="grdSourseImage" ItemTemplate="{StaticResource imgSourceDataTemplate}" HorizontalAlignment="Left" Margin="449,578,0,0" VerticalAlignment="Top" Width="841" Height="160"/>
        <TextBlock HorizontalAlignment="Center" Margin="671,503,316,0" TextAlignment="Center" FontSize="35" TextWrapping="Wrap" Text="Desserts" VerticalAlignment="Top" Width="379" Height="42" Foreground="#FF0A0909"/>

    </Grid>
</Page>


main page.cs code

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;
using System.Collections.ObjectModel;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Deserts
{
    
    public class customImage
    {
        public string imgURL { get; set; }
        public string imgName { get; set; }
        public bool isEnabled { get; set; }
        public customImage(string url, string name, bool enable = true)
        {
            imgURL = url;
            imgName = name;
            isEnabled = enable;
        }
    }
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        ObservableCollection<customImage> sourceImage = new ObservableCollection<customImage>();
        public MainPage()
        {
            this.InitializeComponent();
            sourceImage.Add(new customImage("Assets/1.jpg", "0"));
            sourceImage.Add(new customImage("Assets/2.jpg", "1"));
            sourceImage.Add(new customImage("Assets/3.jpg", "2"));
            sourceImage.Add(new customImage("Assets/4.jpg", "3"));
            sourceImage.Add(new customImage("Assets/5.jpg", "4"));
            grdSourseImage.ItemsSource = sourceImage;
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        private void Image_tabbed_1(object sender,TappedRoutedEventArgs e)
        {
            Image clickedImage=sender as Image;
            String FrameToNavigate=clickedImage.Tag.ToString().Replace("Assets/","");
            FrameToNavigate=FrameToNavigate.Replace(".jpg","");
            switch(FrameToNavigate)
            {
                case "1":
                    Frame.Navigate(typeof(ChocolateCake));
                    break;
                case "2":
                    Frame.Navigate(typeof(Cookiesundae));
                    break;
                case "3":
                    Frame.Navigate(typeof(CreamPie));
                    break;
                case "4":
                    Frame.Navigate(typeof(PistachioDelight));
                    break;
                case "5":
                    Frame.Navigate(typeof(PumpkinDreamPie));
                    break;
            }
        }

    }
}



chocolatecake xaml code

<Page
    x:Class="Deserts.ChocolateCake"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Deserts"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="#FF96D823" VerticalAlignment="Center" HorizontalAlignment="Center" Height="671" Margin="50,44,62,53" Width="1254">
        <Image Source ="Assets/2.jpg"  Height="476" Margin="36,39,615,39"  Width="471"/>
        <Grid HorizontalAlignment="Left" Height="476" Margin="673,98,0,0" VerticalAlignment="Top" Width="475">

            <TextBlock Text="Chocolate Cake" Grid.Row="0" FontSize="48" FontWeight="Bold"/>
            <TextBlock TextWrapping="Wrap" FontSize="23" Margin="0,103,0,-58">
                <Run Text="1. Beat sugar and oil together till creamy"/>
                <LineBreak/>
                <Run Text="2. Beat the eggs lightly  "/>
                <LineBreak/>
                <Run Text="3. Sift the flour, cocoa,soda and baking pwd and mix together  "/>
                <LineBreak/>
                <Run Text="4. Fold in the flour-cocoa mix into the sugar-oil mix alternately adding the egg and milk  "/>
                <LineBreak/>
                <Run Text="5. Add salt and vanilla essense  "/>
                <LineBreak/>
                <Run Text="6. Microwave in a round pyrex baking dish uncovered for 12 mins on med-high.allow 3-4 mins standing time  "/>
                <LineBreak/>
                <Run Text="7. Top with grated milk chocolate when still hot. "/>
                <LineBreak/>
                <Run Text=" 8. Best served with vanilla ice-cream "/>
            </TextBlock>


        </Grid>
        <Button HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Click="Button_Click" Style="{StaticResource BackButtonStyle}"/>

    </Grid>

</Page>

chocolatecake.cs code
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;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Deserts
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class ChocolateCake : Page
    {
        public ChocolateCake()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Frame.Navigate(typeof(MainPage));
        }
    }
}


cookiesundae xam;l code

<Page
    x:Class="Deserts.Cookiesundae"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Deserts"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="#ff96d823" RenderTransformOrigin="0.556,0.501">
        <Image Source ="Assets/1.jpg" HorizontalAlignment="Left" Height="265" Margin="104,268,0,0" VerticalAlignment="Top" Width="344"/>
        <TextBlock Text="                                                         Cookie Sundae Cake"  Grid.Row="0" FontSize="48" FontWeight="Bold" Margin="0,106,0,-106"/>
        <TextBlock TextWrapping="Wrap" FontSize="23" Margin="527,268,0,-58">
                <Run Text="1. Prepare and bake cake mix as directed for 13x9-inch cake. Cool slightly. Turn out on sheet of aluminum foil. Cool completely; set aside.  "/>
                <LineBreak/>
                <Run Text="2. In large bowl, stir together sweetened condensed milk, chocolate syrup. Fold in whipped cream. Pour into aluminum foil-lined 13x9-inch baking pan.  "/>
                <LineBreak/>
                <Run Text="3. Freeze for 6 hours. Lift ice cream out of pan with foil; turn out evenly on top of cake layer. Quickly frost top and sides with whipped topping. Drizzle with chocolate syrup.  Return to freezer at least 2 hours before serving.  "/>
        </TextBlock>
        <Button HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Click="Button_Click" Style="{StaticResource BackButtonStyle}"/>

    </Grid>
</Page>

cookiesundae.cs code

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;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Deserts
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class Cookiesundae : Page
    {
        public Cookiesundae()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Frame.Navigate(typeof(MainPage));
        }
    }
}


creampie xal code

<Page
    x:Class="Deserts.CreamPie"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Deserts"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="#FF96D823" VerticalAlignment="Center" HorizontalAlignment="Center" Height="671" Margin="50,44,62,53" Width="1254">
        <Image Source ="Assets/3.jpg"  Height="476" Margin="36,39,615,39"  Width="471"/>
        <Grid HorizontalAlignment="Left" Height="476" Margin="673,98,0,0" VerticalAlignment="Top" Width="475">

            <TextBlock Text="Cream Pie" Grid.Row="0" FontSize="48" FontWeight="Bold"/>
            <TextBlock TextWrapping="Wrap" Grid.Row="1" FontSize="23" Margin="0,67,0,-58">
                <Run Text="1. Preheat oven to 425 degrees F (220 degrees C).  "/>
                <LineBreak/>
                <Run Text="2. In a large bowl, combine sugars, flour, salt, cream, eggs, and vanilla. Mix until smooth. Pour filling into an unbaked pie shell.  "/>
                <LineBreak/>
                <Run Text="3. Bake for 20 minutes in preheated oven. Lower the temperature to 325 degrees F (165 degrees C), and bake for an additional 20 minutes. "/>
            </TextBlock>

        </Grid>

        <Button HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Click="Button_Click" Style="{StaticResource BackButtonStyle}"/>
    </Grid>
 
</Page>

creampie.cs code

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;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Deserts
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class CreamPie : Page
    {
        public CreamPie()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Frame.Navigate(typeof(MainPage));
        }
    }
}


pistachiodelight xaml code

<Page
    x:Class="Deserts.PistachioDelight"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Deserts"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="#FF96D823" VerticalAlignment="Center" HorizontalAlignment="Center" Height="671" Margin="50,44,62,53" Width="1254">
        <Image Source ="Assets/4.jpg"  Height="476" Margin="36,39,615,39"  Width="471"/>
        <Grid HorizontalAlignment="Left" Height="476" Margin="673,98,0,0" VerticalAlignment="Top" Width="475">

            <TextBlock Text="Pistachio Delight" Grid.Row="0" FontSize="48" FontWeight="Bold"/>
            <TextBlock TextWrapping="Wrap" FontSize="23" Margin="0,67,0,-58">
                <Run Text="1. Preheat oven to 425 degrees F (220 degrees C).  "/>
                <LineBreak/>
                <Run Text="2. In a large bowl, combine sugars, flour, salt, cream, eggs, and vanilla. Mix until smooth. Pour filling into an unbaked pie shell.  "/>
                <LineBreak/>
                <Run Text="3. Bake for 20 minutes in preheated oven. Lower the temperature to 325 degrees F (165 degrees C), and bake for an additional 20 minutes. "/>
            </TextBlock>

        </Grid>
        <Button HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Click="Button_Click" Style="{StaticResource BackButtonStyle}"/>
    </Grid>
  
</Page>

pistachiodelight.cs codeusing 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;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Deserts
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class PistachioDelight : Page
    {
        public PistachioDelight()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Frame.Navigate(typeof(MainPage));
        }
    }
}


pumpkindreampie xaml code

<Page
    x:Class="Deserts.PumpkinDreamPie"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Deserts"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="#FF96D823" VerticalAlignment="Center" HorizontalAlignment="Center" Height="671" Margin="50,44,62,53" Width="1254">
        <Image Source ="Assets/5.jpg"  Height="476" Margin="36,39,615,39"  Width="471"/>
        <Grid HorizontalAlignment="Left" Height="476" Margin="673,98,0,0" VerticalAlignment="Top" Width="475">

            <TextBlock Text="Pumpkin Dream Pie" Grid.Row="0" FontSize="48" FontWeight="Bold"/>
            <TextBlock TextWrapping="Wrap" FontSize="23" Margin="0,67,0,-58">
                <Run Text="1. Preheat oven to 350 degrees F (175 degrees C). "/>
                <LineBreak/>
                <Run Text="2. In a medium bowl whisk together egg, sugar substitute, and pumpkin pie spice until well blended. Add pumpkin and milk to egg mixture, and stir until smooth. Pour mixture into pie shell.  "/>
                <LineBreak/>
                <Run Text="3. Place pie on a baking sheet and bake in preheated oven for 30 minutes, or until set in center. "/>
            </TextBlock>

        </Grid>
        <Button HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Click="Button_Click" Style="{StaticResource BackButtonStyle}"/>
    </Grid>
   
</Page>

pumpkindreampie.cs code

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;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Deserts
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class PumpkinDreamPie : Page
    {
        public PumpkinDreamPie()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Frame.Navigate(typeof(MainPage));
        }
    }
}

CHAPTER 3 EX 04 Steve Dishes App

Ex4) Steve has to develop a Windows Store app for displaying the various dishes available in a restraurant.the expected interface of the app is shown in he following figure.
It is expected that whenever an item is selected from the list present on the left side,the corresponding information is displayed on the right side of the app page.However,Steve is not able to implement this functionality in the app.When he selects an item from the list,he does not see any information on the right side.
Help Steve find out the reason and solution for the preceding problem.
Prerequisite:To perform this exercise,you need the Exercise04.zip file,which contains the source code for the preceding app.Ask your faculty to provide the file.

Ans 4) c# code


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;
using Windows.UI.Xaml.Media.Imaging;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Dishes
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
        private void lst_selectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lst.SelectedItem.ToString() == "1")
            {
                img.Source = new BitmapImage(new Uri("ms-appx:///Assets/1.jpg"));
                head.Text = "1";
                para.Text = "Fresh juicy has burgers at a pocket-friendly of";
            }
            else if (lst.SelectedItem.ToString() == "2")
            {
                img.Source = new BitmapImage(new Uri("ms-appx:///Assets/2.jpg"));
                head.Text = "2";
                para.Text = "Mouth-watering cheesy sandwiches at a price of 2$";
            }
            else if (lst.SelectedItem.ToString() == "3")
            {
                img.Source = new BitmapImage(new Uri("ms-appx:///Assets/3.jpg"));
                head.Text = "3";
                para.Text = "Traditional Noodles at a price of 3$";
            }
            else if (lst.SelectedItem.ToString() == "4")
            {
                img.Source = new BitmapImage(new Uri("ms-appx:///Assets/4.jpg"));
                head.Text = "4";
                para.Text = "Zesty summary Pasta Salad at a price of 2$";
            }
            else if (lst.SelectedItem.ToString() == "5")
            {
                img.Source = new BitmapImage(new Uri("ms-appx:///Assets/5.jpg"));
                head.Text = "5";
                para.Text = "Lip smscking classic pizza at a rate of 5$";
            }

        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>



        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            lst.Items.Add("1");
            lst.Items.Add("2");
            lst.Items.Add("3");
            lst.Items.Add("4");
            lst.Items.Add("5");
        }

    }
}


paste in mainpage.xaml


<Page
    x:Class="Dishes.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Dishes"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="#FFD007F0">
        <ListView  x:Name="lst" HorizontalAlignment="Left" Height="688" Margin="64,46,0,0" VerticalAlignment="Top" Width="337"  FontSize="24" SelectionChanged="lst_selectionChanged">

        </ListView>
        <Viewbox>
            <StackPanel x:Name="stk" Orientation="Vertical" Margin="722,10,100,34" Width="458">
                <Image x:Name="img" Source="" HorizontalAlignment="Left"  Margin="20,20,0,20" VerticalAlignment="Top" />
                <TextBlock x:Name="head" Text="" FontSize="40" Margin="20,20,62,20" FontWeight="Bold" />
                <TextBlock x:Name="para" TextWrapping="Wrap" Text="" FontSize="30" Margin="20,20,62,20"/>
            </StackPanel>
        </Viewbox>
    </Grid>
</Page>

CHAPTER 3 EX 03 Rhea Temperature to celcius

Ex3) Rhea has designed an app that should convert the temperature specified in Celsius to the corresponding tempertaure in Fahrenheit and vice versa.The interface of the app is shown in the following figure.
Rhea wants to implement the following functionalities in the app:
 (1)When the user enters temperature in the Celsius text box,the corresponding temperature in Fahrenheit     should be displayed in the Fahrenheit textbox and vice versa.
 (2)If the value entered in a text box is deleted,the other text box is updated accordingly.
 (3)If the user enters any value other than a number or.(Dot) in one of the text boxes,the invalid input message should be displayed in the other text box.
However,while testing the app,Rhea finds that the fahrenheit text box is not updated when a number is entered in the Celsius text box and VICE VERSA.
Help Rhea identify the reason behind this problem and provide the solution for the same.
Prerequisite:To perform this exercise,you need the Exercise03.zip file,whhich contains the source code for the preceding app.Ask your faculty to provide the file.

Ans 3) c# code

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;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace degree
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
        private void txtDegreeCelsius_KeyUp(object sender,KeyRoutedEventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtDegreeCelsius.Text.Trim()))
                    txtDegreeFahrenheit.Text = (Convert.ToDouble(txtDegreeCelsius.Text)*(9.0 / 5.0)  + 32);

                else
                {
                    txtDegreeFahrenheit.Text = "";
                }
            }
            catch(Exception ex)
            {
                txtDegreeFahrenheit.Text="Invalid input";
            }
        }

            private void txtDegreeFahrenheit_KeyUp(object sender,KeyRoutedEventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtDegreeFahrenheit.Text.Trim()))
                    txtDegreeFahrenheit.Text = (Convert.ToDouble(txtDegreeFahrenheit.Text)+32*(5.0 / 9.0));
                else
                    txtDegreeFahrenheit.Text = "";
            }
            catch(Exception ex)
            {
                txtDegreeCelsius.Text="Invalid input";
            }
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>

    }
}


Xaml code 

<Page
    x:Class="degree.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:degree"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">


        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Margin="-1,5,10,-48">
            <TextBlock Text="Celsius" FontSize="40" Margin="79,201,918,559"></TextBlock>
            <TextBox x:Name="txtDegreeCelsius" FontSize="50" Margin="79,282,191,469" KeyUp="txtDegreeCelsius_KeyUp"></TextBox>
            <TextBlock Text="Fahrenheit" FontSize="40" Margin="79,396,1024,339"/>
        <TextBox x:Name="txtDegreeFahrenheit" FontSize="50" Margin="79,500,164,251" KeyUp="txtDegreeFahrenheit_KeyUp"/>
    </Grid>
</Page>

CHAPTER 3 EX 02 Sam Piano App

Ex 2) Sam,a Windows Store app developer,wants to create a simple piano app for children.He expects the interface of the piano to look like the one shown in the following figure.
Sam has creted the desired interface of the app.
Now,he wants to include the basic music notes in the piano.In addition,he intends to implement certain functionality in the piano,which plays a music note when a piano button is pressed.Help sam create the preceding app.
Prerequisite:to perform the preceding exercise,you need the following files:
 a.wav,b.wav,c.wav,d.wav,e.wav,f.wav,g.wav,Exercise02.zip

Ans 2) Paste in Mainpage.xaml







<Page
    x:Class="Piano1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Piano1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="400"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Image Grid.Row="0" Grid.Column="0" Source="Assets/Background.jpg" Stretch="UniformToFill" Margin="-2,0,2,120"/>
        <Rectangle Grid.Column="0" Height="20" Margin="0,260,0,120">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFF7F7EB" Offset="1"/>
                    <GradientStop Color="#FFEDF70D"/>
                </LinearGradientBrush>
            </Rectangle.Fill>

        </Rectangle>
        <Grid Grid.Column="0" Margin="0,280,0,0" Grid.RowSpan="3">
            <Grid x:Name="grdChordButtons" Tapped="grdChordButtons_Tapped">
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <Button Background="White" x:Name="C" FontSize="60" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="White" x:Name="D" FontSize="60" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="White" x:Name="E" FontSize="60" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="White" x:Name="F" FontSize="60" Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="White" x:Name="G" FontSize="60" Grid.Column="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="White" x:Name="A" FontSize="60" Grid.Column="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="White" x:Name="B" FontSize="60" Grid.Column="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="White" x:Name="c" FontSize="60" Grid.Column="7" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
            </Grid>
            <Grid x:Name="grdBlackChordButtons" Height="320" VerticalAlignment="Top" Margin="95,0,86,0">
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition ></ColumnDefinition>
                    <ColumnDefinition ></ColumnDefinition>
                    <ColumnDefinition ></ColumnDefinition>
                    <ColumnDefinition ></ColumnDefinition>
                    <ColumnDefinition ></ColumnDefinition>
                    <ColumnDefinition ></ColumnDefinition>
                    <ColumnDefinition ></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <Rectangle Fill="Black" Width="100" Stroke="Black" StrokeThickness="2" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
                <Rectangle Fill="Black" Width="100" Stroke="Black" StrokeThickness="2" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
                <Rectangle Fill="Black" Width="100" Stroke="Black" StrokeThickness="2" Grid.Column="2" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
                <Rectangle Fill="Black" Width="100" Stroke="Black" StrokeThickness="2" Grid.Column="3" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
                <Rectangle Fill="Black" Width="100" Stroke="Black" StrokeThickness="2" Grid.Column="4" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
                <Rectangle Fill="Black" Width="100" Stroke="Black" StrokeThickness="2" Grid.Column="5" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
                <Rectangle Fill="Black" Width="100"  Stroke="Black" StrokeThickness="2" Grid.Column="6" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
                <Rectangle Fill="Black" Width="100" Stroke="Black" StrokeThickness="2" Grid.Column="7" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></Rectangle>
                <Button Background="Black" x:Name="bC" FontSize="60" Width="100" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="Black" x:Name="bD" FontSize="60" Width="100" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="Black" x:Name="bE" FontSize="60" Width="100" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="Black" x:Name="bF" FontSize="60" Width="100" Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="Black" x:Name="bG" FontSize="60" Width="100" Grid.Column="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="Black" x:Name="bA" FontSize="60" Width="100" Grid.Column="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>
                <Button Background="Black" x:Name="bB" FontSize="60" Width="100" Grid.Column="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0"></Button>

            </Grid>

        </Grid>
        <MediaElement  x:Name="pianoChordPlayer" HorizontalAlignment="Left" Height="100" Margin="1084,257,0,0" VerticalAlignment="Top" Width="100" Balance="0.5" Stereo3DVideoRenderMode="Stereo" Tapped="grdChordButtons_Tapped" />
    </Grid>
</Page>




C# Code 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;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Piano1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }


        private void grdChordButtons_Tapped(object sender, TappedRoutedEventArgs e)
    {
       UIElement controls = e.OriginalSource as UIElement;
       Button bttnChord = null;
       while (controls != null && controls !=sender as UIElement)
       {
        if(controls is Button)
         {
             bttnChord = controls as Button;
             break;
         }
         controls = VisualTreeHelper.GetParent(controls) as UIElement;
    }
     if (bttnChord !=null)
    {
     pianoChordPlayer.Source = new Uri("ms-appx:///Assets/" + bttnChord.Name + ".wav");
     pianoChordPlayer.Play();
    }
        }


            private void grdBlackChordButtons_Tapped(object sender, TappedRoutedEventArgs e)
    {
       UIElement controls = e.OriginalSource as UIElement;
       Button bttnChord = null;
       while (controls != null && controls !=sender as UIElement)
       {
        if(controls is Button)
         {
             bttnChord = controls as Button;
             break;
         }
         controls = VisualTreeHelper.GetParent(controls) as UIElement;
    }
     if(bttnChord !=null)
    {
     string bttnName = bttnChord.Name;
     pianoChordPlayer.Source = new Uri("as-appx:///Assets/" + bttnChord.Name + ".wav");
     pianoChordPlayer.Play();
    }
}
}
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
     
     
        }