programming4us
programming4us
MOBILE

Windows Phone 7 Development : Building a Trial Application (part 1) - Building the User Interface

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
2/21/2011 11:43:22 AM
The trial software application that you will build in this section is a currency converter. It calls a web service to obtain the current exchange rate for the currencies a user specifies, and then tells users how much of the desired currency they will receive in exchange for the currency they wish to exchange. If the application is running with a trial license, users will be able to convert currencies for free.

However, as we all know, consumers never get the official market exchange rates. Various middlemen take a decent-size cut of foreign exchange transactions, so to calculate the actual amount of foreign currency you can expect to receive, the full application provides another screen, called the "More Stuff" screen. With "More Stuff," users can enter the actual exchange rate quoted by an exchange broker and see how much foreign currency they will receive after they have paid a commission. This "More Stuff" screen will be available only to those who have paid you $.99 and acquired the full version of the application. Future enhancements to this application could include maps, shared between all users of this application, that show the best places to exchange currency around town, with the commission rates as a percentage of the transaction charged by those places. Power to the consumers at last!

To create this application, you will employ several Windows Phone 7 techniques that we cover in this book. As we introduce such features, we will point to the location in the book that you can refer to for more in-depth coverage of the material. We will also emphasize the functionality that is available and disabled with an application running with a trial license, and we will utilize the approach that we have covered in this book to simulate both trial and full license modes and to ensure that our application functions correctly under both.

Now let's build and test the application.

1. Building the User Interface

The Currency Converter application includes three pages: one for the main application screen that performs currency conversions; one to prompt the user to upgrade to the full application license the application is running under a trial license; and one for additional options, such as determining how much money you actually lose on a conversion. In this section, you will create each of these pages. Follow these steps to create a Currency Converter project and add application pages:

  1. Launch Visual Studio 2010 Express for Windows Phone, and create a new Windows Phone Application project. Name it "CurrencyConversion."

  2. Make sure MainPage.xaml is open in Design view. For MainPage.xaml, the end goal is to have a screen with a layout similar to the one shown in Figure 1. The screen looks a little busy, so we will go over each screen element, one by one, to understand the type of the element and element's name. Element names and types will be referred to from code and, hence, are important to get right. Table 1 summarizes field names and types. A portion of the XAML code that creates the "Amount to Convert" text box, two list boxes, and the corresponding captions is shown here:

    Figure 1. Currency Converter MainPage.xaml page layout
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,14,0,0"
    Name="textBlock1" Text="Amount to Convert" VerticalAlignment="Top" />
    <TextBox Height="68" HorizontalAlignment="Left" Margin="6,36,0,0"
    Name="txtAmountToConvert" Text="" VerticalAlignment="Top" Width="446" />
    <ListBox Height="93" HorizontalAlignment="Left" Margin="24,137,0,0"
    Name="lstConvertFrom" VerticalAlignment="Top" Width="220" />
    <TextBlock Height="30" HorizontalAlignment="Left" Margin="24,101,0,0"
    Name="textBlock2" Text="Convert from (currency)" VerticalAlignment="Top" Width="220" />
    <TextBlock Height="28" HorizontalAlignment="Left" Margin="262,101,0,0"
    Name="textBlock3" Text="Convert to (currency)" VerticalAlignment="Top" Width="190" />
    <ListBox Height="93" HorizontalAlignment="Left" Margin="263,137,0,0"
    Name="lstConvertTo" VerticalAlignment="Top" Width="205" />


    Table 1. User Controls for MainPage.xaml
    Application FieldField NameField Type
    Amount to ConverttxtAmountToConvertTextBox
    Convert from (currency)lstConvertFromListBox
    Convert to (currency)lstConvertToListBox
    StatustxtStatusTextBlock
    Total ConvertedtxtTotalConvertedTextBlock
    Convert ButtonbtnConvertButton
    More Stuff ButtonbtnMoreOptionsButton

Next, add the "nag" page, or the page that will try to get users to purchase the full version of our application if the user is executing our application under a trial license.

  1. To do that, right-click the project name in Solution Explorer and select Add => New Item => Windows Phone Portrait Page. Name the page Upgrade.xaml and select OK.

  2. Bring up the design surface of the Upgrade.xaml page, and make it look like Figure 2.

The page consists of a message and two buttons. The message prompts the user to upgrade. One of the buttons enables the user to purchase a full license, and the other one simply returns the user to the main application screen. Ensure that the buttons are properly named by verifying their names with Table 11-2:

Table 2. User Controls for Upgrade.xaml
Application FieldField NameField Type
Yes, upgradebtnUpgradeButton
No, take me backbtnGoBackButton

Figure 2. The "nag" screen layout

Finally, add the "More Stuff" page, or the page that will display features available only to paid users. Sadly, the users of our application will most likely feel cheated at the moment: our only feature available to them will be the calculation of the money they do not get as a result of using the currency conversion services.

  1. To add the "More Stuff" page, right-click the project name in Solution Explorer and select Add => New Item => Windows Phone Portrait Page. Name the page MoreStuff.xaml and select OK.

  2. Bring up the design surface of the MoreStuff.xaml page, and make it look like Figure 3. Refer to Table 3 field names and types:

    Figure 3. The "More Stuff" screen layout with functionality available to full-license users only
Table 3. User Controls for MoreStuff.xaml
Application FieldField NameField Type
Exchange Rate QuotedtxtExchangeRateQuotedTextBox
Calculate DamagebtnCalculateDamageButton
Back to MainbtnBackToMainButton
Total damagetxtDamageExplainedTextBlock

With design layout complete, you are now ready to add code to the application. In the next section, you will add code feature-by-feature, starting with a reference to the web service that supplies current exchange rates.

Other  
  •  jQuery 1.3 : Table Manipulation - Sorting and paging (part 2) : Server-side pagination & JavaScript pagination
  •  jQuery 1.3 : Table Manipulation - Sorting and paging (part 1) : Server-side sorting & JavaScript sorting
  •  Windows Phone 7 Development : Understanding Trial and Full Modes (part 3) - Simulating Application Trial and Full Modes
  •  Windows Phone 7 Development : Understanding Trial and Full Modes (part 2) - Using the Marketplace APIs
  •  Windows Phone 7 Development : Understanding Trial and Full Modes (part 1) - Using the IsTrial Method
  •  Mobile Application Security : SymbianOS Security - Application Packaging
  •  Mobile Application Security : SymbianOS Security - Code Security
  •  iPhone Application Development : Getting the User’s Attention - Generating Alerts
  •  iPhone Application Development : Getting the User’s Attention - Exploring User Alert Methods
  •  iPhone Application Development : Using Advanced Interface Objects and Views - Using Scrolling Views
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us
    programming4us
     
     
    programming4us