Welcome!

Industrial IoT Authors: Pat Romanski, Elizabeth White, Maria C. Horton, Liz McMillan, Ed Featherston

Blog Feed Post

Android to Windows Phone 8 Part 6: Creating a Second Page

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!

In the previous lesson you created a simple UI that accepts text from a user. In this lesson you’ll create a second page in your application to display the user’s input.

Create the Second Page

Right-click the project in Solution Explorer, click Add, and click New Item.

In the Add New Item dialog, select Windows Phone under Visual C#.

Select the Windows Phone Portrait Page template, give the page a name of SecondPage.xaml, and click Add.

You should now see SecondPage.xaml in Solution Explorer.

If SecondPage.xaml is not open, double-click it.

Remove the content from the outermost <Grid> element. You should end up with something that looks like this:


<!–LayoutRoot is the root grid where all page content is placed–>


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

 


</Grid>

Add a <TextBlock> element to the grid:

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


<TextBlock x:Name=”messageFromUser” />


</Grid>

 

Respond to the Send Button

You now need to get the message from the first page to the second page. Start by opening up MaingPage.xaml.

To respond to the <Button> element’s Click attribute to the element

<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}}”


Click=”sendButton_Click”/>

</StackPanel>

</Grid>

ANDROID HINT

The Click attribute is similar to the android:onClick attribute of the Android <Button> element.

 

Open the code-behind file for MainPage.xaml (MainPage.xaml.cs) and add the following method:

private
void sendButton_Click(object sender, RoutedEventArgs e)

{

 

}

VISUAL STUDIO TIP

You can open a code-behind file for a file you’re working with in design view by pressing F7.

 

Now you need to do three things.

  1. Get the text the user entered.
  2. Create a URI to navigate to SecondPage.xaml that includes the text entered by the user. This is done by including the text as a query string parameter.
  3. Navigate to SecondPage.xaml.

All three can be accomplished by adding the following to the sendButton_Click method:

private void sendButton_Click(object sender, RoutedEventArgs e)

{


//Get the message from the <TextBox> element


var message = this.theMessage.Text;

 


//Use a default message if none is provide


if (string.IsNullOrEmpty(message))

message = “Hello World!”;

 


//Create the uri to navigate to SecondPage.xaml, passing


//the message through in the query string


var uri = new Uri(string.Format(“/SecondPage.xaml?message={0}”, message),

UriKind.Relative);

 


//Perform the navigation


this.NavigationService.Navigate(uri);

}

 

ANDROID HINT

In Android you would create an Intent and call the startActivity method to navigate to the second page with code similar to the following:

 

public void sendButton_Click(View view) {

Intent intent = new Intent(this, SecondPageActivity.class);

startActivity(intent);

}

 

If you run your app now (F5) and press the button, you’ll notice that you go to the second page. We’ll work on displaying the message in the last part of this lesson.

Display the Message

Now that you’re able to navigate to SecondPage.xaml from MainPage.xaml you need to display the message the user entered.

Open SecondPage.xaml.cs (the code-behind file for SecondPage.xaml).

Add an override for the OnNavigatedTo method


protected
override
void OnNavigatedTo(NavigationEventArgs e)

{


base.OnNavigatedTo(e);

}

 

Finally retrieve the query string parameter from the page’s NavigationContext property and display in the <TextBlock> element with the following code:

protected override void OnNavigatedTo(NavigationEventArgs e)

{

base.OnNavigatedTo(e);

 


//Check that the query string contains the message parameter


//and display on the page if found


if (this.NavigationContext.QueryString.ContainsKey(“message”))


this.messageFromUser.Text =


this.NavigationContext.QueryString["message"];

}

Run the app (F5) to see the results!

Conclusion

Congratulations! You just build your first Windows Phone application. To learn more about building Windows Store apps, continue to follow this series. The next installment is Working with Data.

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
  • Building a Simple User Interface

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
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
JETRO showcased Japan Digital Transformation Pavilion at SYS-CON's 21st International Cloud Expo® at the Santa Clara Convention Center in Santa Clara, CA. The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get...
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
"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.
As data explodes in quantity, importance and from new sources, the need for managing and protecting data residing across physical, virtual, and cloud environments grow with it. Managing data includes protecting it, indexing and classifying it for true, long-term management, compliance and E-Discovery. Commvault can ensure this with a single pane of glass solution – whether in a private cloud, a Service Provider delivered public cloud or a hybrid cloud environment – across the heterogeneous enter...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
More and more brands have jumped on the IoT bandwagon. We have an excess of wearables – activity trackers, smartwatches, smart glasses and sneakers, and more that track seemingly endless datapoints. However, most consumers have no idea what “IoT” means. Creating more wearables that track data shouldn't be the aim of brands; delivering meaningful, tangible relevance to their users should be. We're in a period in which the IoT pendulum is still swinging. Initially, it swung toward "smart for smart...
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and ...
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
"We are a well-established player in the application life cycle management market and we also have a very strong version control product," stated Flint Brenton, CEO of CollabNet,, in this SYS-CON.tv interview at 18th Cloud Expo at the Javits Center in New York City, NY.
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 ...
Most people haven’t heard the word, “gamification,” even though they probably, and perhaps unwittingly, participate in it every day. Gamification is “the process of adding games or game-like elements to something (as a task) so as to encourage participation.” Further, gamification is about bringing game mechanics – rules, constructs, processes, and methods – into the real world in an effort to engage people. In his session at @ThingsExpo, Robert Endo, owner and engagement manager of Intrepid D...