Thursday, October 21, 2010

Windows Phone 7 – facebook OAuth Update

On the final day before I wanted to submit a Windows Phone 7 application, the facebook integration functionality suddenly stopped working.  I was receiving an error message after the user logs in.  This also broke an application I had already completed so I knew something had to change on the facebook side of the equation.

After pulling my hair out for over a week and correspondence with the facebook development team I identified the issue.  To get this feature working again, I simply needed to add “IsScriptEnabled=true” to the browser element in XAML so it looks like:

image

With this in place my authentication magically started working again. :P

Here’s hoping this save someone a little bit of time.

-twb

Thursday, October 14, 2010

Micro ISV + Windows Phone 7 + Azure = WFA (Work From Anywhere)

If you can’t tell by my latest series of blog posts (that I’ll pickup once again after I ship) I’m very excited about Windows Phone 7.  Being a Micro ISV the concept of building applications on a phone that we can directly market is very appealing especially considering the size of the audience.

So here is my goal, I want to WFA (work from anywhere) with my primary location being a 40’ sail boat down in the Florida Keys.  Windows Phone 7 is one side of this equation, the other is Azure.  Most interesting Windows Phone 7 applications will need some sort of server component.  As an Micro ISV I have three realistic choices (now that I don’t have a T1 line and standby generators in my garage) buy hardware and host at a data center.  Get a VM instance running by some provider, or my new current favorite, host it in the cloud.  After working on all three major contenders, I feel pretty strongly that the Azure model bests fits the needs of a fast moving ISV.

Hosting in cloud has the benefits of not having to wear and IT hat or hire someone to install patches and defrag the disk.  The cloud also provides a path towards scalability.  My first app might not be the one that brings in the millions, it might be the second, third or fourth one.  Or I might be working on the fifth one and my second app gets picked up by C-NET without my knowledge and suddenly I have an extra 2 million users accessing my service.  With a cloud based solution I can simply buy more computing power.  My philosophy is if I’m getting 500K+ hits a day the cost of ramping up instances is (or better be) a rounding error.

If you’re located even remotely near Tampa and want to learn more about Azure you MUST check out Azure Firestarter – Tampa – November 2008.  Tampa will be the only Azure Firestarter in Florida.  If you're into Azure it spells out "worth the roadtrip" from other cities.

-twb

Wednesday, October 6, 2010

Windows Phone 7 Quick Tip #17 – Enable/Disable Menu Bar

Here’s another quick one I ran into while testing my application.  I need to submit data to a web service and wait for a response.  While they phone is talking to the web service, I don’t want the user to send the same request twice.  Initiating the send takes place on the app bar.

image

We need to disable the app bar button.  If you attempt to use the control name you assign to the button it will throw a null reference exception.  Not a very good UX.  My initial solution that I put in place and held my nose was similar to:

((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Enabled = false;

Don’t get me started on what I don’t like about that approach, ok?

I came across an instance where I needed to disable two buttons, I just couldn’t handle the smell of:

((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Enabled = false;((ApplicationBarIconButton)ApplicationBar.Buttons[1]).Enabled = false;

And decided to do something about it.  My solution is a simple extension method that looks like:

namespace Microsoft.Phone.Shell
{
    public static class ApplicationBarHelpers
    {
        public static void Enable(this IApplicationBar appBar)
        {
            appBar.IsMenuEnabled = true;

            foreach (var obj in appBar.Buttons)
            {
                var button = obj as ApplicationBarIconButton;
                if (button != null)
                    button.IsEnabled = true;
            }
        }

        public static void Disable(this IApplicationBar appBar)
        {
            appBar.IsMenuEnabled = false;

            foreach (var obj in appBar.Buttons)
            {
                var button = obj as ApplicationBarIconButton;
                if (button != null)
                    button.IsEnabled = false;
            }
        }
    }
}

Something still smells above…should be able to get rid of some lines of code but don’t want to get too side tracked.  Kudo’s and a mention to anyone that can do a little cleanup.

Just include the using Microsoft.Phone.Shell to pickup the namespace within your .cs file and you can do the following:

 

ApplicationBar.Enable();

and

ApplicationBar.Disable();

Which I think is much cleaner.

-twb

Windows Phone 7 Quick Tip #16 – Visual Studio .NET and Isolated Storage getting deleted

If you are developing a Windows Phone 7 application that uses Isolated Storage you may notice while using Visual Studio that your storage files get “nuked” or deleted at random times.  Well like me you probably realized that it isn’t random but weren’t able to identify the pattern.  While exchanging emails with Nick Randolph from down under he suggested that it was when you Rebuild, rather than Build, it will nuke your local storage files.  Thirty seconds later I was able to confirm this and life is grand and I can save that minute or so that it takes to restore my settings. =D

-twb

UPDATED: from Reddy Duggempudi of Microsoft:

Clean build (rebuild or clean/build) will reinstall the app which in turn will remove all the “old  app” artifacts such as Isolated storage.

Windows Phone 7 Quick Tip #15 – Five Minute Guide to Globalization

Globalizing your Windows Phone 7 Application will allow you to reach a much wider audience.  With the approach Microsoft is taking in there marketplace, this could mean the difference between your app making $500 or potentially > $1000 a month.  Globalizing your application is actually fairly simple but is much easier if you do from the start.  Globalization is much more than just translating the strings in your application, in addition you should also take a look at Localization Best Practices for Windows Phone for additional pointers.  This quick tip will just show you how to setup your project so you can start using String Resources rather than just putting the text the for the TextBoxes in your application.  Do this when you start your application, not at the tail end.  Hear me now, believe later :)

Our goal is to eliminate this:

<TextBlock Text="HelloWorld" />

And pull that string from here:

image

Here are the simple steps:

  1. Add a resource file to your project.
  2. I usually drag under the folder Properties, it just seems at home there.
  3. Open the resource file and add name value pair, the name goes in the first column and will be used to refer to your resource in XAML, the value is the default languages string.

Then change the Access Modifier to Public:

image

Next create a class that will create a static instance of the resources within your application.  The static class should be similar to:

using System;
using ResourceSample.Properties;

namespace ResourceSample
{
    public class StringResources
    {
        private static AppResources _resources;

        public static AppResources LocalizedResources
        {
            get
            {
                if (_resources == null)
                    _resources = new AppResources();

                return _resources;
            }
        }
    }
}

Then we need to create a static resource for this class in the App.xaml file.

image

Finally instead of this:

<TextBlock Text="HelloWorld" />

You can do this:

image

Once you have all the text for your application in a resource file, you can package up and deploy additional as described here.

Bonus Tip: Click here for how to localize the application title for your Windows Phone 7 application.

-twb

Windows Phone 7 Quick Tip #14 – Metro Part IV – Be Authentically Digital

WTF you might be saying?  Authentically Digital?  Let me explain.  Long before the current crop of phones and user interfaces tried to mimic the real world with leather textured backgrounds and fun 3D effects, science fiction embraced the concept of the _future_ and tried to make their predictions of what user interfaces might look like.  This can be seen in the following control panel from Star Trek TNG.

One of the core design principles of your user interface for a Windows Phone 7 application is that it should be authentically digital.  It shouldn’t try to be something it’s not.  Your Windows Phone 7 is a portal into your “stuff”, nothing more.  It should provide the most efficient, and cleanest way of pleasantly getting you to your “stuff” without getting in the way.  Don’t try to mimic the real world with backgrounds that look like leather or the texture of blue jeans, no fancy gradients (did you hear me DevFish).  Provide a minimalistic interface so that your users can get to their stuff and get back to their lives.  As much as we like to be appreciated as developers, we are not serving our community well if we try to write our applications so that every time our users open our app and they say, “Wow, what a cool user interface”.  We should strive for them to want to use our apps so they can say “Wow, look what little Sally did at school today”. 

-twb

Monday, October 4, 2010

Saying Goodbye to being a Device Application Development MVP

And say hello to becoming a Windows Phone Development MVP. 

I’m very excited about this new opportunity and even more excited to start blogging about the applications I’ve been working on!

-twb

Windows Phone 7 Quick Tip #13 – Metro Part III – Design Resources

Microsoft has published an awesome PDF with the specifics of how your User Interface should implement petty much every standard control you could have in your app.  You can download the PDF as well as additional templates here.  The additional templates are in Adobe Photoshop format.  Those templates can be opened with Expression Design.  Once you open these templates, you get a very high precision pixel layout that you can reference to answer all your layout questions.

Before you starting building your application it’s a good idea to go through this document, it’s only 29 pages long, however it is easier to put the control on the page correctly the first time rather than having to go back in and rework your application.  Trust me, I know from experience :).

Microsoft has also published some pretty darn good Windows User Experience Design Principles, these apply equally if not more to a Windows Phone 7 application.

Another resources is the Windows Phone 7 Design Templates out on CodePlex.  These is a indows Phone 7 project that do a good job of showing specific implementations of the controls.  To compile this, you will also need the Windows Phone 7 Silverlight toolkit which if you haven’t downloaded and reviewed you should.  It contains some missing controls like a Date and Time picker, ToggleSwitch, Context Menu, Gesture support and a WrapPanel.

-twb

Saturday, October 2, 2010

100s of more Reasons why Windows Phone 7 will Fail

Last month The Wolf Bytes brought you a desktop version of a tool to for everyone that is convinced that Windows Phone 7 will fail, but is just too darn busy to try it for themselves.  This month comes a version for the actual device itself.

Download the XAP file.

Enjoy

-twb

Windows Phone 7 Quick Tip #12 – Metro Part II – Built in Resources

In our previous quick tip we made the point that using the built in color theme is really an all or nothing decision.  This quick tip will discuss some of the built-in resources that allow you to follow those built in theme.

Microsoft has kindly published a list that lists all of the resources in the built in resource dictionary that are available to us developers.  Here is a quick over view on how to apply resources to your Windows Phone application.

It’s fairly trivial on how to apply any of these resources into your XAML, simply reference them as a static resource like

<TextBlock Text=”Hello Windows Phone” Foreground=”{StaticResource PhoneForegroundColor}” />

Sometimes you need to build up some of the controls for your page in the code behind section.  If so you can still access the resources.  It’s still simple, but not quite as obvious.  You can get access to the resources with the following chunk of code:

var backgroundColor = (Color)Application.Current.Resources["PhoneBackgroundColor"];

Finally you should be aware that when you create a new page or user control in Visual Studio 2010 with a built in template it will automatically help you out by add the resources to the UserControl or PhoneApplicationPage definition such as:

<phone:PhoneApplicationPage
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"

In summary, using built in resources helps you with your primary goal of making your application feel like it belongs on the phone.

-twb