Monday 24 February 2014

Rhea has designed an app that should convert the temperature specified in Celsius to the corresponding temperature in Fahrenheit and vice versa. The interface of the app is shown in the following figure.


Rhea has designed an app that should convert the temperature specified in Celsius to the
corresponding temperature in Fahrenheit and vice versa. The interface of the app is shown in the
following figure.
The Interface of the App
Rhea wants to implement the following functionalities in the app:
When the user enters temperature in the Celsius text box, the corresponding temperature in
Fahrenheit should be displayed in the Fahrenheit text box and vice versa.
If the value entered in a text box is deleted, the other text box is updated accordingly.
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.

Solution:

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

    <Viewbox>
        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Height="900" Width="1600">
            <TextBlock Text="Celsius" FontSize="100" Margin="122,122,1002,668"></TextBlock>
            <TextBox x:Name="txtDegreeCelsius" FontSize="70" Margin="122,237,121,554" keyUp="txtDegreeCelsius_KeyUp"></TextBox>
            <TextBlock Text="Fahrenheit" FontSize="100" Margin="122,463,931,326"/>
            <TextBox x:Name="txtDegreeFahrenheit" FontSize="70" Margin="122,582,121,209" keyUp="txtDegreeCelsius_KeyUp" />
        </Grid>
    </Viewbox>
</Page>

"
--------------------------------------------------------------------------------
CS FILE 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 ConverterApp
{
    /// <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, KeyRoutedEventArge e)
        {
         try
          {
              if (!string.IsnullOrEmpty(txtDegreeCelsius.Text.Trim()))
                  txtDegreeFahrenheit.Text = (Convert.ToDouble(txtDegreeCelsius.));
              else
                 txtDegreeFahrenheit.text = "";
          }
          catch (Exception ex)
           {
           txtDegreeFahrenheit.text ="Invalid input";
           }
        }
       
       private void txtDegreeCelsius_KeyUp(object sender, KeyRoutedEventArge e)
        {
         try
          {
              if (!string.IsnullOrEmpty(txtDegreeCelsius.Text.Trim()))
                  txtDegreeFahrenheit.Text = (Convert.ToDouble(txtDegreeCelsius.));
              else
                 txtDegreeFahrenheit.text = "";
          }
          catch (Exception ex)
           {
           txtDegreeFahrenheit.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>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
    }
}
"

No comments:

Post a Comment