Welcome!

Industrial IoT Authors: Elizabeth White, Stackify Blog, Yeshim Deniz, SmartBear Blog, Liz McMillan

Blog Feed Post

Android to Windows Phone 8 Part 5: Building a Simple User Interface

Over the past several weeks I’ve been working on some content I’m excited to finally share with you through a series of blog posts. This series will introduce you to Windows Phone 8 development from an Android developer’s perspective. Through the course of the series you’ll create your first app. It won’t be anything pretty, but you’ll learn the ins and outs of the development environment, how to create a simple user interface, and how to perform navigation. Along the way you’ll see some Android Hints that will help make it easier for you to transition your existing skills to the Windows Phone platform. You’ll also see some Visual Studio Tips to make you more productive in your development environment. Good luck!

A Windows Phone application is simply a collection of pages. A page is the interface seen by the end user.

ANDROID HINT

A page is similar to an Activity in Android development

 

Each page is designed for the end user to interact with the application. A page is composed of layout controls and various widgets. Only one page can be seen by the end user at a time.

ANDROID HINT

Like Android there is a system level “Back” button in Windows Phone.

 

To better familiarize yourself with the user interface components of a Windows Phone application the following table maps Android widgets to their Windows Store counterparts:

Purpose

Android

Windows Store

Display Text

TextView

TextBlock

Edit Text

EditText

TextBox

Radio Button

RadioButton

RadioButton

Check Box

CheckBox

CheckBox

Submit

Button

Button

Show Progress

ProgressBar

ProgressBar

Display a List of Components

LinearLayout

StackPanel

Vertical List of Components

ListView

ListView

2-Dimensionl Grid

GridView

Grid

Display an Image

ImageView

Image

 

This is by no means an extensive list. As with many development technologies there are a number of ways to perform the same task. For example, instead of using a ListView to display a vertical list in a Windows Phone app I could simply use a StackPanel and set its orientation property accordingly.

In this lesson you’ll learn how to create a simple interface for your Windows Phone application.

Add a Text Field

For your UI you’ll want a label to tell the user what to do, a field where users can input text, and a button. You’ll start by adding the text field.

Open the MainPage.xaml file in the root directory of your project.

VISUAL STUDIO TIP

When you open a *.xaml file you’ll first see a split view. The left view contains a visual designer. This lets you build layouts using WYSIWYG tools. The right view contains the markup generated by the designer. For this lesson, you’re going to work directly with the XAML. To give yourself more screenspace you can go to a “XAML only” view using the following steps.

  1. Click the button on the toolbar between the designer and the markup view. This will move the markup view to the left and designer view to the right.
  2. Click the button on the toolbar between the two views. This will minimize the designer.

 

You’ll notice that Visual Studio adds quite a bit to the markup for a page when it is created. For simplicity we’re going to delete most of it. Delete everything within the outermost <Grid> element of the page. You should end up with something that looks like this:


<Grid x:Name=”LayoutRoot” Background=”Transparent”>

 


</Grid>

Add a <StackPanel> element to the <Grid> element:


<Grid x:Name=”LayoutRoot” Background=”Transparent”>


<StackPanel x:Name=”theStackPanel”


Orientation=”Vertical”>


</StackPanel>

</Grid>

ANDROID HINT

A StackPanel is equivalent to a LinearLayout in Android development. It allows you to lay out child elements in either a verity or horizontal orientation.

 

The x:Name attribute is similar to the android:id attribute. However, you are not required to provide a x:Name attribute for your visual elements.

 

The Orientation attribute is identical to the android:Orientation attribute of the LinearLayout in Android. The default value for the Orientation attribute is Vertical.

 

Now add a <TextBox> element inside of the <StackPanel> element you just created. Be sure to provide a x:Name attribute for it. You should end up with something like this:

<Grid x:Name=”LayoutRoot” Background=”Transparent”>

<StackPanel x:Name=”theStackPanel”

Orientation=”Vertical”>


<TextBox x:Name=”theMessage” />

</StackPanel>

<Grid>

 

Add String Resources

Next you’ll want to add a label to your page to instruct the user on what to do. You might be tempted to add a <TextBlock> element and sent its Text attribute to the text you want displayed. While this will work, it goes against best practices for localization.

Start by opening the AppResources.resx file by double clicking it in Solution Explorer.

You’ll see several resources were defined when Visual Studio create the project. To add an additional resource, simply enter it on the last line of the editor. You should end up with something like this:

Add a Label

With the Resource file in place you’re now ready to add the label to your page.

Open MainPage.xaml if not’s not already open and add a <TextBlock> element above the <TextBox> element in the <StackPanel> like this:

<Grid x:Name=”LayoutRoot” Background=”Transparent”>

<StackPanel x:Name=”theStackPanel”

Orientation=”Vertical”>


<TextBlock x:Name=”theLabel”


Text=”{Binding Path=LocalizedResources.MessageLabelText,


Source={StaticResource LocalizedStrings}}” />

<TextBox x:Name=”theMessage” />

</StackPanel>

</Grid>

The Text attribute specifies the text the element will display. You need to do two things:

  1. Specify where the string resides (Source={StaticResource LocalizedStrings}).
  2. Specify the name of the specific string you want to use (Binding Path=LocalizedResources.MessageLabelText).

Add a Button

The last thing you’ll need to do as part of this lesson is to add a <Button> element to the page so you can send the message the user enters to a second page.

Before you add the <Button> be sure to add a string resource for its Content property in the AppResources.resx file.

Now add a <Button> element under the <TextBox> element in MainPage.xaml, being sure to specify the appropriate Content attribute for localization.

<Grid x:Name=”LayoutRoot” Background=”Transparent”>

<StackPanel x:Name=”theStackPanel”

Orientation=”Vertical”>

<TextBlock x:Name=”theLabel”

Text=”{Binding Path=LocalizedResources.MessageLabelText,

Source={StaticResource LocalizedStrings}}” />

<TextBox x:Name=”theMessage” />


<Button x:Name=”sendButton”


Content=”{Binding Path=LocalizedResources.SendButtonText,


Source={StaticResource LocalizedStrings}}” />

</StackPanel>

</Grid>

Congratulations! You just created your first Windows Store UI. It might not be pretty, but it works. You can run your app now (press F5 or F6 to see the results).

Previous Posts in this Series

  • Setting up the Development Environment
  • Creating Your First Windows Phone Project
  • Exploring the Windows Phone Project
  • Running the Windows Phone Application

Additional Resources

Read the original blog entry...

More Stories By Adam Grocholski

Hey there! My name is Adam Grocholski, and I'm a Technical Evangelist at Microsoft where I spend time focusing on Windows, Windows Phone, and Windows Azure. I live in the frozen tundra of Minnesota and run thinkfirstcodelater.com. You can also follow me on twitter at @codel8r.

@ThingsExpo Stories
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...