Navigating around windows phone 7

Vermeer-the-Astronomer

Navigation in Silverlight applications for Windows Phone is simpler, if somewhat more constrained, than in Silverlight applications for the web. 

In classic Silverlight applications the template on which we build our pages is the UserControl.  User controls are set as the root visual for the applications and, at least before Silverlight 3, navigation was typically handled by replacing one user control with another.

Silverlight 3 introduced a special navigation control.  While the root visual for a Silverlight application was still a user control, the user control could host a navigation “Frame”.  The frame, in turn, hosts “pages”, which are just specialized user controls.

Silverlight for Windows Phone adopts the navigation scheme exemplified by the latter set of classes: frames and pages.  It also simplifies it.  Instead of hosting the navigation frame in a page, a specialized class called a PhoneApplicationFrame is the root visual in a WP7 application.  It, in turn, hosts a variety of PhoneApplicationPages.

It is helpful to think of the PhoneApplicationFrame as a web browser.  Like a web browser, it never changes when you move between pages.  Instead it acts as a viewer for the pages you want to navigate between.  You navigate between pages, in turn, simply by passing a uri to the browser.

The PhoneApplicationFrame is typically set in the app.xaml file (though it can also be set programmatically).  The Source attribute of the frame is set to the uri for the initial PhoneApplicationPage.

<Application.RootVisual>
        <phoneNavigation:PhoneApplicationFrame 
        x:Name="RootFrame" 
        Source="/MainPage.xaml"/>
    </Application.RootVisual>

So how do we navigate between different pages in our application? 

1. One way is to simply use a HyperlinkButton control.  The NavigateUri attribute can be set to the location of another PhoneApplicationPage (in this case, the MyView page in the root of my application).  When the user clicks on the link, the root frame will navigate to the new page. 

<HyperlinkButton Content="HyperlinkButton"  
                     Name="MyViewLink"
                     NavigateUri="/MyView.xaml" />

You will want to include the initial slash in your path.  If you don’t, the phone application will open up a mini-browser and attempt to navigate to the specified uri on the web.  For instance, if the NavigateUri above is set to “bing.com”, the mini-browser will come up on the phone and display the following page:

minibrowser

2. Like the Silverlight Button control, HyperlinkButton uses the Content property to set the text for the hyperlink.  Like the Silverlight Button control, anything can be set to the Content.  This means we can use a trick familiar from web development to make an hyperlink look like something else – for instance, an image.

You can create a hyperlink like this:

hyperlink

simply by stacking some controls inside the content of your HyperlinkButton like so:

<HyperlinkButton Name="hyperlinkButton1"  
                    NavigateUri="/MyView.xaml" >
    <Border BorderBrush="White"
            BorderThickness="5"
            Padding="10">
    <StackPanel Orientation="Horizontal">
    <Image Width="60" 
            Source="/phoneapp1;component/Images/appbar.next.rest.png" />
        <TextBlock VerticalAlignment="Center" 
        Text="Go to View.xaml"></TextBlock>
    </StackPanel>
    </Border>
</HyperlinkButton>

3. You can also programmatically navigate between pages.  If your navigation is in the code-behind for a PhoneApplicationPage, you can take advantage of the NavigationService property of your page – which happens to return a System.Windows.Navigation.NavigationService instance.  This service will not only navigate to a page you specify, but will also maintain a history of pages visited in case the end-user decides to use the Windows Phone back button.

 

    this.NavigationService.Navigate(
        new System.Uri(
            "/MyView.xaml"
            ,System.UriKind.RelativeOrAbsolute)
            );

4.  If your navigation code needs to be placed somewhere other than in the code-behind for a PhoneApplicationPage – for instance in a UserControl – things become slightly more complicated.  In this case, the navigation service can be accessed through the PhoneApplicationFrame, which is the root visual for Windows Phone 7 applications.  The Frame has a Navigate method that calls the same NavigationService object we grabbed previously through the page.  The following example accesses the Frame’s navigation method from a Command on a ViewModel.

private void GoToMyView()
{
    var root = App.Current.RootVisual
        as PhoneApplicationFrame;
    root.Navigate(
        new System.Uri("/MyView.xaml"
        ,System.UriKind.RelativeOrAbsolute)
        );
}
private ICommand _navigationCommand;
public ICommand NavigationCommand{
    get
    {
        if (null == _navigationCommand)
        {
            _navigationCommand = new RelayCommand(GoToMyView);
        }
        return _navigationCommand;
    }
}

5. You can finally just change the source property on the PhoneApplicationFrame in order to navigate to a new page.  This is functionally equivalent to calling the Frame.Navigate method – in fact, changing the source property throws an event that ultimately calls the Frame.Navigate method.  The above code can be rewritten to this functionally equivalent code:

var root = App.Current.RootVisual
    as PhoneApplicationFrame;
root.Source =
    new System.Uri("/MyView.xaml"
    ,System.UriKind.RelativeOrAbsolute);

Thank you Codestock

I greatly enjoyed the Codestock conference this year.  The new venue is definitely a move in the right direction.  Downtown Knoxville is a fantastic area – at least once I got oriented and discovered Market Street.

I mentioned several tools during my Advanced Windows Phone 7 development talk.  Here are the links:

To replace the default Windows Phone image with unlocked WP7 image (build 6176), follow this link:  http://www.multiupload.com/POF771XDFD .  Drop the image into C:\Program Files (x86)\Microsoft SDKs\WindowsPhone\v7.0\Emulation\Images and rename it wm70C1.bin .

For the application bar icons go here: http://www.microsoft.com/downloads/details.aspx?FamilyID=369B20F7-9D30-4CFF-8A1B-F80901B2DA93&displaylang=en

Stephane Crozatier’s implementation of the Pivot Control and Panorama Control (variations on the Hub concept) can be downloaded here: http://phone.codeplex.com/

Laurent Bugnion’s MVVM Lite framework, which includes templates for Windows Phone, is available here: http://mvvmlight.codeplex.com/ 

Be sure to review the Windows Phone UI Design and Interaction Guidelines: http://go.microsoft.com/?linkid=9713252

I also want to point everyone to a fantastic resource for learning Windows Phone Silverlight development I recently discovered.  It is Roberto Brunetti’s blog.  It is in Italian but is nevertheless fairly easy to follow thanks to his excellent use of images and code samples: http://thinkmobile.it/blogs/rob/ .

Natural User Interface and Semiotics

phone7_icons

The icons above are prescribed (promoted?) for Windows Phone 7 development.

When dealing with limited screen real estate, it is important to use what space one has effectively.  One way to accomplish this is to use icons rather than text to cue the user about the functionality of a phone application.

Iconography is intimately tied to the development of what people are calling the Natural User Interface (NUI) which is to be distinguished from the Graphical User Interface (GUI) that has predominated in software devices and PC’s since the mid-90’s.

The main input device for GUI’s has (let us say, in a qualified manner, “always”) been the mouse.  The main input device for NUI’s, on the other hand, is the finger, facilitated by touch sensitive devices and touch recognition software.

(Missing from these moments in the evolution of the software interface is Speech UI, which has never seemed to catch on.  This was the dominant UI foreseen by precogs of the 50’s and 60’s.  In part this may have been due to the fact that SUI is a technology that can easily be described in print sci-fi literature, whereas a NUI interface is less so.  A generation raised up on Star Trek – to which we are indebted for the design of our cell phones as well as the sliding doors at Walmart – thought it was a sure thing.  Strangely it has been largely skipped over at the very time when the processing power of computers and devices makes it plausible.  One possible explanation for this is that it simply took too long to get the hardware up to snuff and another generation of designers – one influenced by Tom Cruise’s The Minority Report rather than Star Trek – came along.  With advances in CGI, NUI is much more compelling than SUI in movies, and discards the print-based underpinnings of speech UI.  Another possibility, however, is that Speech Recognition simply got bogged down by the baggage of AI and the desire not only to make speech interfaces effective but also to give them a personality.)

So what makes a Natural User Interface natural?  For one thing, it removes the input device – whether a mouse or a keyboard – as the intermediary between the user and the device.  It is an unmediated interface.

But is this truly more natural?  Isn’t one of the definitions of humanity that we are tool using creatures.  Our interaction with the world is always mediated by tools that extend our natural capabilities.  We have swords in place of claws, books in place of memory, and wireless keyboard\mouse combinations in place of … what?  Fingers?

Looking at this from a different perspective, one of the criteria for the success of NUI will be that people intuitively understand how to use it.  For this, however, more will be required than simply having touch sensitive devices.  The UI’s created with NUI must also be intuitive.  People must be able to use an application without first reading the manual (which they haven’t done for generations, anyways).

Here we have an opening for a discussion of semiotics.  Semiotics is simply the study of signs.  (Tom Hanks — the other Tom —plays a semiotician in the Dan Brown inspired movies, though he is not called that.)  The study of signs includes language.  It includes codes.  It especially includes icons.

One of the common observations about signs is that they are natural and universal.

One can look at Egyptian hieroglyphics and, even without a Rosetta stone, have a feeling that one understands them.  Smoke always indicates fire.  Red, in the natural world, seems to often indicate danger.  An arrow seems to always draw one’s attention in a certain direction: up, down, left, right.  We intuitively understand why our distant ancestors used signs as a primitive form of writing – the meaning can be culled out of symbols without apparent cultural context.  Symbols (and gestures) can be used to communicate when there is no other common language between people.

One of the remarkable observations discovered by Semiotics as a professional discipline is that there is always a cultural aspect to signs.  Even in using simple signs, two people have to quickly agree, in the moment, on what they mean by apparently obvious glyphs.  Does a yellow light mean “slow down” or “speed up”?  When I point do I mean this item here or the one slightly to its left?  When I laugh, am I laughing with you or at you? 

All meaning is based on agreement.  As Umberto Eco might put it, we know this because we can disagree about meaning.  The definition of a sign, then, is not simply something that stands for something else, but rather something that can be misunderstood.

In designing glyphs for the Windows Phone 7 device, then, we must work with signs that can be misunderstood and are obligated to try to make them univocal in meaning.  This is one reason why the designers of the WP7 platform strongly recommend that everyone use this particular set of icons.  If everyone uses the same glyphs, there is less room for misunderstanding.

The requirement that we all come to a common understanding of what these glyphs represent also opens up the possibility that the meaning of these glyphs will change over time.  There is also the theoretical possibility that these glyphs currently mean nothing at all.  Each glyph is simply an arrangement of pixels.  It will be up to Windows Phone application designers to determine how they should be used.

Paul L. Snyder, a friend on the “Semiotics and Technology” forum, makes the following observations about these signs:

Consider the types of symbols in this collection.  We have:

* Symbols that depict a particular object, with the intent of evoking an association with that object’s primary function (an SLR camera, an envelope, an film-driven movie camera, a file folder, a present, a trash can, a pencil)

* Symbols that suggest a general idea, in the hopes that it can be related to a contextual activity (a minus sign, a plus sign, arrows, a check mark, an ‘X’, a star, a question mark)

* Symbols that rely primarily on already-established conventions outside of the computer realm (play/pause/ff/rewind)

* Composite symbols that try to suggest a more complicated idea (a star with a superimposed ‘+’, arrows pointing to a bar, two curved arrows suggesting a loop

It’s interesting to consider these symbols in light of the theory of ‘icons’ that Umberto Eco critiques in chapter 3 (see p.191, I know we aren’t there yet). Clearly, these icons are striving to be icons in a similar sense, as they are intended to:

* have the same properties as their objects,

* be similar to their objects,

* be analogous to their objects, or

* be motivated by their objects

(though I’m less sure about that last one).  Each of the symbols (with the possible exception of the large circle, for which I can’t guess a probable meaning) is hoping to rely on pre-existing culturally-coded conventions, with lesser or greater degrees of similitude.  By providing a hook that is "similar" to the action that the icon is intended to indicate, the hope is to make it easier for the user to store a mental model of these associations.  In some cases (such as the gear) this may be quite loose.  It’s interesting that several of the icons (movie camera, floppy disk) used depictions of outmoded technology in an attempt to make their meaning clearer.

Perhaps one thing that semiotics can do here is to point us to the culturally coded nature of the associations being used, which can be a starting point for assessing the probably efficacy of the symbol selections (though even so, nothing is a substitute for actual end-user testing).

Learning to program Windows Phone 7

Scribe

The Windows Phone 7 platform is so new, there is still a dearth of material for learning to program on it.  Pete Brown and Jesse Liberty have opined that if you know Silverlight then you are already a WP7 developer.  This is true up to a point.  If you already know how to program Silverlight or XNA you definitely have a leg up.  But as everyone knows, it’s that last mile that counts.

I’ve previously recommended Charles Petzold’s preview for his upcoming book Programming Windows Phone 7 Series.

It provides a pretty thorough overview of the technology and gives equal air-time to both Silverlight as well as XNA.  Plus Charles Petzold is a pleasure to read.

I would also highly recommend the WP7 Training Kit provided by Channel 9.

The WP7 Training Kit provides code and tutorials that walk you through the basic (and a little bit of advanced) skills you’ll need to start building Silverlight-based WP7 apps.  Mercifully, it goes beyond the Hello World level of Windows Phone 7 tutorial that is currently prevalent on the web.

You should also, of course, hit the Windows Phone forums to see what other people are discovering.  Mark Chamberlain posted a great list of WP7 links on the forum for code samples and code walkthroughs.

If you randomly browse the web for Windows Phone help, I want to warn you in advance of Windows Phone tutorials that turn out to be Silverlight tutorials simply transposed for the phone.  If you see one of these, run.  Run fast.

Free Windows Phone 7 Devices

startscreen_print

According to the twitter rumor mill, certificates for free Windows Phone 7 devices are being handed out to select attendees at this year’s Tech-Ed North America in New Orleans (to be accurate 50 of them, according to Brandon Watson).

Looking past some of the grumbling from a few MIX10 attendees who feel they should have gotten a shot at the phones (we all got free Azure t-shirts left in our hotel rooms, didn’t we?), this is very exciting news.  It suggests that a large number of Windows Phone devices are ready and will soon become available to WP7 developers.

<hypothetical>WP7 DEVICES for Phone application developers will soon be generally – more or less — AVAILABLE!  Woohoo!</hypothetical>

For the past month or so I’ve been peering at these devices over the shoulders of Microsoft evangelists.  At MIX I surreptitiously saw one hanging out of the pocket of a project manager on the Phone team.  I don’t think I even saw one at the MVP Summit in February.

So how does one get one’s hands on the upcoming series of phones for developers?  I have no hard information, but a good bet is to sign up for the Windows Phone Marketplace.

It’s $99 for a year – a very good price if you plan to develop Windows Phone applications in time for the Holiday launch later this year.  And if, by chance, that registration puts you on a list to potentially get a WP7 device – well that’s just gravy, isn’t it?

The big message I’m hearing, though, is that you should really come up with a great idea for a phone app before asking for a phone.  Microsoft isn’t looking to hand out phones so you can, only at that point, start thinking about what you might want to build.  That would be putting the cart before the handheld device.

Speaking at DevLink

Our far-flung correspondent from self-promotion land writes:

I received an invitation this past week to speak at DevLink.  I will be presenting on two topics:

The C# 4 Dynamic Objects session will be a longer version of the talk I gave at the MVP Summit in February.  The Advanced Windows Phone 7 talk is one I find I am updating every few weeks as more tools and information about the platform become available.

DevLink is a three day conference being held in Nashville, August 5-7.

Your First Windows Phone Development Book

WinPhone_v3_18432D37

Shortly after the announcement at MIX that the Windows Phone Developer Tools were available for download, a free e-book by Charles Petzold on developing for Windows Phone showed up on the Internet.  You can download it from his site here.  It includes six chapters from the book and, from what I’ve read so far, is great.  The XPS I downloaded is 156 pages – so it is quite a bit more than a tease.

The book begins in Petzold’s characteristically off-center and brilliant style:

“This is a short draft preview of a much longer ebook that will be completed and published later this year. That later edition will be brilliantly conceived, exquisitely structured, elegantly written, delightfully witty, and refreshingly free of bugs, but this draft preview is none of that. It is very obviously a work-in-progress that was created under an impossible timeframe while targeting quickly evolving software.”

Windows Phone Developer Tools and Silverlight 4 Released

jackpot

Scott Guthrie announced at the MIX10 keynote this morning that the Developer Tools for Wndows Phone Series 7 are now available for download.  You can get the tools here at http://developer.windowsphone.com/windows-phone-7-series/.

Silverlight 4 for the Visual Studio 2010 RC and the Expression Blend Beta are also now available here on www.silverlight.net.

Mr. Guthrie (AKA ‘The Gu’) also announced that Blend 4 will be a free upgrade for licensed owners of Blend 3, which is fantastic news.

The final release for all of these will occur in a month – one assumes it will coincide with the Visual Studio 2010 release on April 12.