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));
        }
    }
}

1 comment:

  1. Genelia has developed a book app, which allows users to read a book and navigate from one
    page to another. The home page of the app is shown in the following figure.
    The Home Page of the App
    The content page of the app is shown in the following figure.
    The Content Page of the App
    However, this app does not allow the users to move back from a page to the previous page.
    Moreover, when the users reach the last page, no control is provided to move back to the home
    page.
    Help Genelia identify the reason behind the preceding problems and provide a solution for the
    same.

    plz send me the awnswer

    ReplyDelete