Archive

Archive for the ‘wp7’ Category

TCSLUG Slide Deck and Code

April 21st, 2010

I’ve uploaded the code and slide deck from my presentation at the Twin Cities Silverlight User Group. You can download the content here.

A couple of quick notes:

  1. The code includes the source for the TekPub media player I demo’d during the presentation.
  2. To build and run the code you need the following installed on your machine:
    1. Microsoft Visual Studio 2010 RC
    2. Windows Phone Developers Tools CTP

Enjoy!

adam wp7 , ,

Windows Phone 7 Series PowerPoint Template

March 26th, 2010

Next month I’ll be presenting at the Twin Cities Silverlight User Group on Windows Phone 7 Series and Silverlight. Here’s the session abstract:

At MIX10 there were a number of announcements and a lot of buzz around Windows Phone 7 and one of its development platforms, Silverlight. While it is undoubtedly tempting to download the CTP bits and start coding, it would be wise to take a step back and come to an understanding of the differences between developing in Silverlight for Windows Phone 7 and developing for traditional (i.e. browser hosted) Silverlight applications.In this session we’ll examine the differences and similarities between the two platforms as well as some other gotchas that come along with developing for Windows Phone 7.

Be sure to register for the event here.

In pulling materials together for the session I thought it’d be nice to have a PowerPoint presentation that had the look and feel of the Windows Phone 7 Series. After hacking around for about 15 minutes I came up with a template that I thought would work. The template consists of two layouts:

wp7_title

(Layout 1: title)

wp7_content

(Layout 2: content)

After creating the template I realized other people are probably throwing together presentations around Windows Phone 7 and they might like to use/modify this template. So I thought I’d just make it available to anyone interested.

Note: The template was created using PowerPoint 2010, and has not been tested for compatibility with PowerPoint 2007.

You can download the template here.

adam presentations, wp7

Introducing Silverlight 3.7!

March 16th, 2010

(Note: I typically don’t tweet my blog posts, but I did so with this one as I want to make sure those following the developments at MIX10 around Windows Phone 7 and Silverlight are aware of some key differences between the platforms.)

Tuesday at MIX10 there was a big release that went completely unannounced Silverlight 3.7 is now in CTP! That’s right 3.7! I can’t believe it! It’s amazing! It’s, uh, um, hey, wait a minute, isn’t the release candidate for Silverlight 4 in the wild?

No, I’m not losing it (well maybe I am, but that’s neither here nor there). In my last post I discussed one of the key shortcomings, in my opinion, of the WP7 platform, the lack of browser support for Silverlight. I pointed this out because my fear is that a lot of people are going to assume that WP7 supports browser hosted Silverlight since native apps can be written for with Silverlight. As a result, people may not be willing to adopt the WP7 platform quickly since they can’t leverage existing Silverlight assets. The goal of this post is to try and show a couple of different ways you can reuse code across both the “browser hosted” and “phone hosted” silverlight platforms.

First we’ll set up a solution with two projects, a Windows Phone application, and a Browser Hosted (Silverlight 4) application:

cxag_ss001_hosts

Next we’ll want to add a project that will contain code we want to reuse across the the two applications. In this case we’ll choose a Silverlight class library project that targets the Silverlight 4 runtime:

cxag_ss002_sl4

Next we’ll want to our two applications projects to reference the class library. Adding a reference to the Browser Hosted application works without problem. However, when we try to add the reference to our Windows Phone project we get the following error:

cxag_ss003_sl4_error

Let’s try the reverse. Let’s first add a Windows Phone class library project:

cxag_ss004_wp7

Now let’s add the project references. Adding the references to the Windows Phone application works as expected, but now the Browser Hosted applications gives us ethe following error:

cxag_ss005_wp7_error

So, what the heck is going on here? To find out we’re going to need to take a peek at the assemblies referenced by our Browser Hosted and Windows Phone application. The assemblies for the Browser Hosted application can be found in the following directory: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0. Let’s choose one assembly to look at. In this case we’ll use the System.Windows.dll. Here are the details of the assembly:

cxag_ss006_systemwindowsdll_sl4

The assemblies for our Windows Phone application can be found in the following directory: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone. If we take a look at the System.Windows.dll assembly in this directory we’ll see the following:

cxag_ss007_systemwindowsdll_wp7

See the difference? Windows Phone uses, what is, essentially, Silverlight 3.7, which is why we can’t add a reference to a Silverlight 4 class library. If you take a look at some of other assemblies in this directory, such as System.Core.dll, you’ll see something like this:

cxag_ss008_systemcoredll_wp7

These core assemblies are actually compiled for the .NET Compact Framework 3.7.10056.0. This is why we’re unable to add a reference to a Windows Phone assembly to our Browser Hosted project.

So, how can we share Silverlight code between our Windows Phone and Browser hosted applications? There are two approaches that initially come to my mind. (I have a third idea involving T4, but that needs to get flushed out yet). The first thing we could do is create a Silverlight 3 class library project:

cxag_ss009_sl3

All we need to do now is add the reference to our two application projects, which will work. However, I don’t like this approach as it’s least common denominator (LCD) programming. We’re actually holding the code in both applications back from full potential by using a lower version of Silverlight.

Another approach is to use linked files. In this case we’ll delete the Person.cs file from our CxAg.Shared.Phone project. We will then add the Person.cs file from the CxAg.Shared.Silverlight4 project to our CxAg.Shared.Phone project as a linked file. The result will look like this:

cxag_ss010_linkedfile

See that little arrow by the Person.cs file? It indicates that it isn’t actually a file, but, rather, a pointer to a file located somewhere else. In our case, it’s just a point to the Person.cs file in the CxAg.Shared.Silverlight4 project.

One thing you’ll want to keep in mind is how to handle code that compiles for one platform, but not for the other. An approach I’ve taken in similar scenarios looks something like this:

cxag_ss011_partialclass

I like to declare my shared classes as partials. These allows me to include platform specific code in each project (as separate, non-linked files) without breaking the build. In my opinion neither of these solutions are ideal, but they’re workable. As I mentioned earlier, I’m working on a third, T4 based solution, but that’s still in progress. Keep in mind too that we’re working with what is, for all respective, purposes a new development platform, so there are kinks to be worked out. I hope this gets you on your way to successful Silverlight 4/Winodws Pohne 7 development!

adam mix10, silverlight, wp7 , ,

Windows Phone 7 and Silverlight Support, A Word of Caution

March 16th, 2010

So, I was at Scott Guthrie’s keynote address at MIX10 yesterday and I walked away scratching my head. On the one hand all the announcements around Windows Phone 7 and its development platform we’re great. I was really glad to see that the tooling falls in line with Microsoft’s history of providing great, integrated tools for developers. I was also happy to see Microsoft breaking away from it’s usual routine and really, I mean, really focus on the user experience. Did they get the UX right? I don’t know. There are bits and pieces I find interesting and other pieces I simply wonder “What were they thinking”, but that’s an entirely different post. The lack of of true “Enterprisey” features other than support for Exchange and Office, also concerns me, but I’m sure those will come in time and with demand. Of course, there’s also the fact that apps don’t really run in the background. However, all of these things aren’t why I was scratching my head yesterday. I was wondering about the elephant in the room. I was wondering why nobody asked the obvisous question. If Windows Phone 7 uses Silverlight as a platform for building native app, will existing “Silverlight-enabled” websites work in the phone’s browser? It seems like such a simple question, one with an obvious answer. But the fact that none of yesterday’s presenters explicitly called it out had me concerned. After all I have some Silverlight apps running around on the interwebs and it would sure be nice if they just worked on Windows Phone 7. People have ripped on that fruit company in Cupertino for a long time for not supporting plug-ins (i.e. Flash or Silverlight) within their mobile broswer, so you think Microsoft would be ready to 1-up them by supporting their own technology (i.e. Silverlight) in the mobile browser of their shiny new device.

Since I didn’t get an answer, I thought I would download the developer bits and give a Silverlight enabled website a go in the WP7 emulator. What better site to use than Silverlight.net. Here’s how the site looks in the desktop version of IE8

slnet_ie8

Notice the area surrounded by red? This is a Silverlight component. Keep this in mind as you now look at the site in the emulator for WP7:

slnet_wp7

See that area in red? That’s where the Silverlight component should be! When I saw this I stepped away from desk thinking that this simply couldn’t be. So I created a Silverlight 4 RC app on my machine and tried to browse to it via the emulator. Same result. Still refusing to believe this, and thinking maybe it was just an emulator issue, I hunted down a Microsoft DPE last night to get confirmation. Unfortunately he confirmed my fears. Windows Phone 7 does not support Silverlight within the browser. Let me say that again so you can hear it:

WINDOWS PHONE 7 DOES NOT SUPPORT SILVERLIGHT IN THE BROWSER

I was very confused, and, quite honestly, viscerally angry about this. It seemed like such a no brainer, and I think it’s an initial assumption a lot, A LOT, of people are going to make. After all, there are a ton of Silverlight apps already deployed on the interwebs, and a number of people are going to assume that they’ll just work in the browser on WP7. After all, wouldn’t be in Microsoft’s best interest to say “You know all those existing Silverlight apps you have, they’ll work too!” I’m also suprised at the lack of support of Silverlight in the WP7 browser for another reason. One of the other things we’ve heard at MIX10 is that there’s not an intial way to distribute your apps outside of the app store/marketplace/whatever. This has raised the ire of a number of corporate developers. Allowing the WP7 browser to support Silverlight would seem to solve this problem. However, it would allow people to bypass the app store for deploying their apps, thus reducing a revenue stream for Microsoft. I’m not saying or event suggesting this is the reason WP7 does not support Silverlight in the browser. I’m sure there are techincal reasons, such as the IE browser on WP7 not supporting plug-ins.

With all of this said, you can reuse code across browser hosted and phone hosted applications. I’ll have an upcoming post on that shortly.

All in all, I think the WP7 platform has a lot of promise and potential, and I’m looking forward to working with it. I hope you are too!

adam mix10, silverlight, wp7 , ,