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>
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>
No comments:
Post a Comment