Rants Tagged with “Silverlight”

If you haven't had a chance to join me for the Silverlight Tour yet, next week is your chance! I will be in Atlanta for the next Silverlight Tour stop.
The Silverlight Tour is a three-day, soup-to-nuts breakdown of Silverlight 4. This includes learning the ins and outs of XAML, hosting in the browser, the tools and using Silverlight on the server. The class utilizes the Silverlight 4 as well as the latest toolset from Microsoft (including Visual Studio 2010 and Expression Blend 4).
The Silverlight Tour Workshop also includes a complimentary license to Telerik's RadControls for Silverlight for every attendee* (a $999.00 value). For more information on RadControls, you can visit there site at http://telerik.com.
For a limited you can get 10% off the price by using the coupon code 'SUMMER2010'. Seats are limited.
If you're in Atlanta tomorrow (July 26th, 2010), i'll be at the Microsoft office in Alpharetta (north of Atlanta) to speak at the Atlanta .NET User's Group. I will be doing a short talk on Silverlight and interacting with the HTML DOM/other Silverlight apps. I'll also be talking about building your first Windows Phone 7 application using the latest Beta tools.
The fun starts at 6pm (though I'll likely not arrive until just at 6:30 for the first talk). You can find directions and other information here:
http://www.atldotnet.org/default.aspx

I am one of the lucky few who received Windows Phone 7 phone this week. For those who will ask, I got a phone because I am writing a book on programming for the Windows Phone 7 (Application Development for the Windows Phone 7 with Silverlight, Addison-Wesley).
My overall first impression is very good. I was able to get e-mail working, XBox Live integration and play with debugging on the phone. This blog entry will exclusively tallk about the phone, not the development experience. I will add new blog entries soon on my experience developing with the phone.
The device I received from Microsoft was one of the LG WP7 phones shown below:

(click image for a full-sized version)
I've done a short video talking about some of the experience with the phone's built-in apps here:
The phone has a slide-out keyboard (like my Droid does) and I like the design a lot:

(click image for a full-sized version)
The buttons are curved so you can tell you're typing on one key instead of more than one (unlike my Droid) and the F and J both have small nubs so I can feel when I am correctly on the home row.
You should notice that the phone has three main buttons on the front of the device:

(click image for a full-sized version)
These three buttons are for going back, going to the main hub (home screen) and launching the search. The back button is a key button for your use of the phone. As you navigate through the phone's apps or pages within an app. This button represents something like a 'back button' in the browser but for the entire OS.
The Windows key (e.g. home button) always returns to the home screen of the application (e.g. the main hub). Finally, the search button takes to you to the Bing app for searching the web. The only thing about the Bing app that I don't like is that it doesn't search the phone too. I would like it to search for contacts or addresses or emails on the device too (Android's Google integration does this). I am hoping this makes it in a post-preview release.
The size of the device is about the same as my Droid, but the screen is noticably smaller (after using the Droid, its obvious, but the resolution is the required 800x480). Also, please ignore the fingerprints:

(click image for a full-sized version)
The widths are about the same too:

(click image for a full-sized version)
The phone has all six buttons required for a device. The three front facing buttons (shown above). The Camera button on the lower right:

(click image for a full-sized version)
The Volume rocker button(s) on the upper left:

(click image for a full-sized version)
Finally the power/sleep button on top:

(click image for a full-sized version)
Sorry for the blurry picture, I couldn't get my camera to take this clear for some reason. The left button is the power/sleep button. Aside from it being in a different place (left side of the top) than my droid, it works well. The phone takes a micro-USB cable for charging/syncing. The placement is unfortunate as it is on the top of the device instead of the bottom as I prefer. Also annoying is the little removable cover for the USB port. Its unnecessary and will likely break soon as I charge/sync a lot.
Overall its a nice preview of the OS that will likely be my main phone coming soon. There are really only two things that stop me from making it my main phone now:
- Lack of apps. This will change at launch and after, but right now there are a few Android apps that I can't live without.
- No Turn-by-Turn navigation. I didn't realize how much I'd grown accustomed to using my phone as my GPS device but I do. I can get maps and directions, but its not the same as the Android's built-in turn-by-turn navigation which is stellar.
I love a lot of the little touches on the phone. I love the way that facebook is integrated into the whole experience and that linking a facebook friend with a contact makes everything that much easier to follow. The home hub is awesome and now I want all my icons on the Droid to be live too. And the panorama (or hub) apps are a welcome change from the page-based apps I live with on the Droid.
In the next part of this series, i'll talk about developing with the phone itself and how debugging works on the phone.

As many of you may have heard, I recently launched http://GiveAQuiz.com as a new web site for creating and taking quizzes. The Data Team at Microsoft were great in helping me build this site. I've written a whitepaper detailing how we used the Microsoft data stack to accomplish it. This whitepaper shows how we used these data technologies to build the site:
If you are using Microsoft's Data stack for your own web-based and/or Silverlight site, give a look...hopefully some lessons learned you can use:
http://msdn.microsoft.com/en-us/library/ff847451.aspx

The new Windows Phone 7 Tools dropped this week and since I am writing a book on the subject, I decided to upgrade immediately. The upgrade was pretty clean. I could repeat a bunch of other bloggers with instructions for migrating your projects to the Beta, but go Google it with Bing™ if that's what you need.
As I am writing a book on the subject, I am less dealing with migrating my applicaitons than seeing what has changed. The first thing I did with the new tools was create a new Windows Phone List Application to see what was new in the way it worked.
For the uninitiated, the Windows Phone List Application is a simple model-driven application that shows a data-bound list of items on a first page and handles navigating to a second page for the details of the individual items. In the CTP version of the template switching pages would cause a page-flip animation to happen that was quite cool to see. The problem was that in the CTP the code that they included in the template was nasty. It was all done at the page level and I am glad to see they removed it. But to my dismay they didn't replace it with anything.
Since I am in the business of doing demos (as evidenced by the upcoming Silverlight for the Windows Phone classes in Atlanta and Seattle), I wanted something sexier to show aspiring students. At the same time I wanted to do it in a better way than the old template code did it.
The way that the page-based applications on the Windows Phone work is with a PhoneApplicationFrame class that hosts the application (deriving from the Navigation Framework's Frame class) and each page is an instance of the PhoneApplicationPage class. In the old template, all the transitions were done at the page level. I wanted something better. It seemed to me that if we could hide the transitions in the frame, it would be mostly transparent. I could have derived from PhoneApplicationFrame do add the transitions, but I thought it was be nicer to use the Silverlight ecosystem to do it right.
To accomplish it, I used styling (at Jeff Wilcox's suggestion) to do the transitions. In the Silverlight Toolkit (remember to use the November 2009 toolkit that is compatible with Silverlight 3), there is a control called the TransitioningContentControl. This control can be used as a traditional content control but allows you to specify the kind of transition that takes place. By overriding the ControlTemplate for the PhoneApplicationFrame, I was able to replace the ContentControl with a TransitioningContentControl:
<Style x:Key="mainFrameStyle"
TargetType="phone:PhoneApplicationFrame">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:PhoneApplicationFrame">
<Border x:Name="ClientArea"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<layout:TransitioningContentControl
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}">
</layout:TransitioningContentControl>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Since Silverlight 3 (which the Phone SDK is based on) does not support implicit styling, we have to apply the style manually. In the Windows Phone List Application project, the frame is created in the App.xaml implementation file (e.g. .cs or .vb file). Inside the InitializePhoneApplication method, I simply added the style to the construction of the frame like so:
// App.xaml.cs
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet;
// this allows the splash
// screen to remain active until the
// application is ready to render.
RootFrame = new PhoneApplicationFrame()
{
// Use a style to use the Template
// with the TransitioningContentControl
Style = (Style)Resources["mainFrameStyle"]
};
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
At this point the transition control worked but the default fadein/fadeout transition was too subtle. I wanted the page-turn transition. To do this, I had to override the TransitioningContentControl's template. Since I was not going to re-use this template, I simply set it as the Template inline in the ControlTemplate for the PhoneApplicationFrame template like so:
<Style x:Key="mainFrameStyle"
TargetType="phone:PhoneApplicationFrame">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:PhoneApplicationFrame">
<Border x:Name="ClientArea"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}">
<layout:TransitioningContentControl
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}">
<layout:TransitioningContentControl.Template>
<ControlTemplate
TargetType="layout:TransitioningContentControl">
<!-- See example code for complete control template
... -->
</ControlTemplate>
</layout:TransitioningContentControl.Template>
</layout:TransitioningContentControl>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Go grab the code and improve on it. I am sure its not perfect:
http://wildermuth.com/downloads/PhoneListWithTransitions.zip

Back in February I wrote an article stating my opinion about the current State of Data Access in Silverlight (then Silverlight 3 and betas of WCF RIA Services and WCF Data Services). Things have improved in some ways since then but they haven't been fixed. Here's my thoughts on the current state:
The three options for data access are still the same "Web Services, WCF Data Services and WCF RIA Services". My major issue with data access today in Silverlight persists: there is no perfect answer. There is give and take with each approach and giving good advice about the right one is difficult. Instead of talking about the right way to do it, let's look at a chart i've been coming up with to simplify it:

(Click to enlarge)
This chart should represent the pros and cons I see with all the technologies. Hopefully this helps you make the decision for your projects.

As some of you have heard, I am working on a Windows Phone 7 book. While most of my time has been spent trying to convince the publisher to let me call it "The Windows Phonebook: Writing Applications for Windows Phone 7, A-Z", I've had the chance to start writing a real application with it. The purpose of the application is to get comfortable with the programming environment but be able to ship a free app at launch that has some value (yeah, I am already signed up for a Marketplace Developer account!).
For this first application, I decided to completely rip off use for inspiration a couple of Android applications that show the current phase of the moon. Writing this simple app was not that difficult (though its not done so I won't be sharing the code yet), but I found that I spent more time trying to get good moon images and a good moon-phase algorithm than I did in getting the Silvelright code to work. Here's the current look of the application:

(click the image for a full sized version)
The idea is simple, show the current day's moon phase and let the user swipe right or left to move the current day and watch the moon change phase. To do this I had to get comfortable with Manipulations.
Manipulations are the way that the Windows Phone 7 SDK communicates the touch interface to the developer. Currently the Manipulations are only available to subclasses of the Control class because the 'events' are exposed as protected virtual methods. This is suboptimal but it does work. I hope this changes in later versions of the SDK.
When using Manipulations, you have three virtual methods you can override (typically in a UserControl or in my case the MainPage which derives from the PhoneApplicationPage class). These methods are:
- OnManipulationStarted
- OnManipulationDelta
- OnManipulationCompleted
In my case I focused on the completion of a Manipulation (swipes) so I only had to deal with one of the methods: OnManipulationCompleted. This virtual method passes in ManipulationCompletedEventArgs object that contains information about the manipulation and the object it was connected to. So in my overriding of the virtual method, the first thing I needed to do was to ensure that the manipulation was directly on the the image of the moon by checking the ManipulationContainer property of the ManipulationCompletedEventArgs:
public partial class MainPage : PhoneApplicationPage
{
// ...
protected override void OnManipulationCompleted(
ManipulationCompletedEventArgs e)
{
base.OnManipulationCompleted(e);
// Ensure its the Moon Picture that is being manipulated
if (e.ManipulationContainer == moonPic)
{
// ...
}
}
// ...
}
Since we cannot (hopefully yet) handle events directly on Controls, I needed to ensure that the swipe happened on the image itself. Now that I knew its on the picture of the moon, I could test to see what kind of swipe occurred if any. The ManipulationCompletedEventArgs has a property called TotalManipulation that exposes the information about the complete touch gesture. The TotalManipulation property is an instance of the ManipulationDelta class. This class exposes two properties that tell you about the type of gesture that was generated. The properties are:
- Translation: The movement of the gesture as in dragging or swiping.
- Scale: The extent of a pinch gesture.
The name of these properties is similiar to their relationship to the Transforms that match the two operations (TranslateTransform and ScaleTransform). With the information in the TotalManipulation, I could determine if a swipe occurred simply by testing to see direction of the swipe (by testing the Translation's X and Y properties):
// If its a swipe right which means that the user
// dragged their finger at least 100 pixels to the right
// and didn't move their finger far to up or down
// (-25 to 25 in the translation)
if (e.TotalManipulation.Translation.X > 100 &&
(e.TotalManipulation.Translation.Y > -25 &&
e.TotalManipulation.Translation.Y < 25))
{
_vm.MoveToNextDay();
SetMoonFrame();
}
// If its a swipe left which means that the user
// dragged their finger at least 100 pixels to the left
// and didn't move their finger far to up or down
// (-25 to 25 in the translation)
if (e.TotalManipulation.Translation.X < -100 &&
(e.TotalManipulation.Translation.Y > -25 &&
e.TotalManipulation.Translation.Y < 25))
{
_vm.MoveToPreviousDay();
SetMoonFrame();
}
In this code I am checking the translation to see where the swipe happened. Checking the X axis was making sure the swipe was at least 100 pixels in length and the Y axis to make sure it was somewhat level swipe. While some are hoping that the raw gesture data will also be exposed by Microsoft for the phone, the simplification of the Manipulation API does make most simple work dead easy to code against.
As I continue working on the book and this (and other) applications, I'll continue this series to hopefully highlight some of the new API's in the WP7 SDK.

So my blog has been pretty quiet lately and I thought I'd let you know why. With a small team, I've been building GiveAQuiz.com.
Several months ago I was working with a client who wanted me to put together a short quiz on Silverlight to help determine which of their developers got to join their Silverlight team. So I did what I always do, I searched the Internet for some small startup site that let's me accomplish the task at hand. Unfortunately all I found were logs of 'survey' sites that would let me put together some questions but only receive summary results. The one site I found that would let me build a quiz, only would let me print a PDF of the quiz to give to people by hand. This got me thinking about how a site that let people give quizzes might not only be helpful to people like me, but also to teachers of all kinds. I was determined to create the site...when I had free time (yeah, I know).
As I had chances, I would do some small part of the planning. When I wrote a SketchFlow article, I used the opportunity to prototype some of the screens for the article. But to get the site really built, I needed help. To the rescue came Microsoft and Chris Sells. Chris and I decided we wanted to build the site in the same spirit as NerdDinner.com. Microsoft would help fund the development of the site and I would write a whitepaper and do some videos on how we built the site.
I put together a small team consisting of Chris Rauber (ASP.NET MVC dev extraordinaire), Dennis Estanislao (designer savant) and myself to build this site. The site is now live, but is in a private beta mode (where you can e-mail me to get an account for a limited number of users) until we get the bugs out.
Building the site was a lot of fun and we got to mix a lot of technologies inlcuding:
From the beginning the expectation was to have the source code available under MS-PL so that it could be an exemplar for other developers to see how a site with the latest Microsoft stack. You can find the current version of the source code on CodePlex at http://giveaquiz.codeplex.com. We are accepting new members to help implement new features after launch so if you're interested in helping, feel free to apply on the CodePlex site. We we do a formal release of code once the private beta is complete. We also used AgileZen.com (who graciously granted us a free license since we were working on an open source project) and using it for workflow between disconnected members turned out really well. Love the product!
So now its your turn, I want to ask you my readers to check out GiveAQuiz.com and ask for a private beta account. The first twenty-five people who contact me at "shawn at giveaquiz dot com" will get into the private beta. Help us find the bugs please!

Hopefully like the rest of you, I am headed to the Big Easy (e.g. New Orleans) for TechEd next week. I think there might be some surprise announcements (though I don't expect all of the stuff that Mr. Forte does).
I will be there to mingle with the crowds and spend some time in the French Quarter (yeah, I know...I am supposed to stay at the booths all day.) I am genuinely estatic that TechEd is returning to what I consider one of the world's great cities.
If you're interested in seeing me, I'll be doing a talk, a BOF and some time at the expert's booth:
Where Will Microsoft Silverlight Take Front-End Development?
When: Tuesday, June 8th, 1:30pm-2:45pm
Where: Room 355
Session Type: Birds-of-a-Feather
Speaker(s): Greg Leonardo, Shawn Wildermuth
Silverlight has expanded options for front-end development for Microsoft .NET developers. Have you worked with Silverlight? Would you like to learn more about it? Come join this session where we share how Silverlight is used, the real scoop on using it, and where we might go with it.
Securing Microsoft Silverlight
When: Wednesday, June 9th, 8:00am-9:15am
Where: Room 281
Session Type: Breakout Session
Track: Web Platform
Speaker(s): Shawn Wildermuth
Level: 300 - Advanced
Silverlight is different. Because Silverlight applications typically live outside the firewall, securing them requires an additional level of finesse. There are several security vectors that must be considered when using Silverlight including securing your application from intruders, eavesdroppers, and users themselves. This means you need to know how to protect your code, your data, and your servers from the nefarious. In this session, Shawn Wildermuth shows you how to protect yourself from these threats.
Silverlight Booth Duty
When: Wednesday, June 9th, 12:15pm-3:00pm
I'll be working the Silverlight Booth to answer your questions on Wednesday as well. Come by with the tough questions...stump the chump is on!

The field of smart phones is getting larger this holiday season: the Microsoft offering is the Windows Phone 7. It should be of no surprise to most people that this category of phone is becoming increasingly important, but not because its a phone.
Many people spout off that the iPad is a category changed, but I think the iPhone was much more important. The hand-held computer is finally a reality. Having great experiences for consumers is the lynchpin of these devices. In this category are really four major players IMHO:
- iPhone by Apple
- Blackberry Phones by RIM
- Android Phones by Google
- Windows Phone 7 by Microsoft
I won't repeat the relative merits and misses that the other players have made, instead i'd like to make a pitch for both consumers that Windows Phone 7 is likely to be a great experience (and until we have final silicon and OS we won't know for sure).
Great Consumer Story
I think Microsoft is finally doing the phone right here. They've repeatedly stated that they will be focusing on the consumer story in this first release. While Microsoft can do and has done a great job focusing on the enterprise, they've struggled with their consumer level products in many areas (XBox notwithstanding). By not trying to solve both masters, this first version should provide a great platform for consumers. They're not being goaded by developers into opening up the platform to features which hurt the consumer experience (e.g. multi-tasking) while working with specific partners on features consumers want (e.g. background audio with Pandora and the like).
In addition, I think that being late to the game will actually help Microsoft this time. Phones are not like other devices. People are not as invested in them (or keep them as long) as other hardware. I firmly think that iPhone-fatigue is setting in. Some of it is the result of Apple's heavy-handedness in control of the AppStore and equally its reluctance to punish AT&T for bad service.
Android equally has other problems with multiple versions of their operating systems and are trying hard to have better control over that. The fact that when you go get an android phone and the average consumer has to know to get a 2.0 or 2.1 phone instead of 1.6 phone is just a travesty. This will ultimately hurt the adoption of the Android phone. While the Apple's AppStore is too tightly run, the Android store is too lose. Android is often called, "iPhone Without Rules". That comes with a cost.
Blackberry is a completely different animal. They've succeeded in the enterprise market and are certainly the big dog in the business sector, but this first Windows Phone isn't targetting them...but I suspect v2 will be all about business users.
But What About Developers?
A lot is made about the developer story on each of the platforms. Apple requiring Objective-C (or other C based coding) does seem shortsighted but at the end of the day the richness of the programming platform is only part of the story.
When I first got my Android phone I wondered how many of the apps that I craved on the iPhone would be on my new phone. I was pleasantly surprised that apps like Shazam and 4Square were already ported to Android. Similarly when the Windows Phone 7 was announced, some of these same apps were demo'd. But the reality is that most of the hard work of these apps aren't on the device. Building a new client for the functionality on the server means that most of the client code is just polish, not functionality in the traditional sense.
Let's use Shazam as an example. Shazam was ported quickly mostly because all it does on the phone is record and play music as well as show data of the songs that were identified. But the detecting of the song information is all done on big iron in the cloud. The radical change in the iPhone then seems to be the ubiquity of the Internet on a phone, not the phone itself. Turn off 3G and Wireless and see how many of your apps continue to work on your phone. Go do it now...i'll wait.
Finished yet?
As you've figured out, many of the apps you use are really the first of the new wave of cloud-based apps. The fact that instead of being web-driven, they are smart-client cloud apps. This affects developers by realizing that they need to get both sides right. A great user experience on the device that is driven by a great cloud experience. The skills required can be pretty varied to get both sides correct. Nothing worse than a great looking app that's waiting on server time-outs.
Late to the Party?
But is Microsoft coming out with their phone after Apple's already plucked the market from under them? Perhaps, but I think quickly coming up with a 'me too' phone would have proven disasterous. Coming late to this part may in fact be the reason for its success. With the relative success of the Android phone has shown, the iPhone is not indominable. In fact, the level of iPhone fatigue I think is at a high point at this time.
While coming late to the party, many people also worried about what Microsoft would come up to complete in this new phone era. The Metro (or Cosmopolitan) design language has thoroughly surprised me. I expected microsoft to just compete not to overtake. The new phone paradigm is still to be tested, but it is my sincere hope that this new hub system works as advertised.
Development Model
Much has been said about Apple's take on how to control their developers (and force their own language requriements). I think this will be ultimately lead to developers flocking to other phones. We are already seeing this on the Android phones as it uses Java and that helps re-use existing skillsets of language and tooling. I expected Microsoft to do something similiar but their decision to use Silverlight was a complete surprise. Using XNA for game development just fits (as that's how XBox Community, Windows and Zune games were written). But Silverlight as the programming model does several things in Microsoft's favor as far as I am concerned:
- Allows existing .NET developers to come to the platform easily.
- Allows existing Silverlight and WPF developers to use their skills seemlessly.
- Promotes cross-usage of assets on the desktop, web and phone.
I've played with the bits in building the course and writing the first chapter of my upcoming book (so I am obviously not a completely neutral party) but I am impressed so far.
I've updated my XBox Games Browser app for the phone to the most recent version (Windows Phone Developer Tools CTP (April 2010 Refresh). The biggest change in this version is that I had to use Tim Heuer's advice (and PowerShell tool) to remove the signing of the OData Library for the phone (I've included that in an externals directory in the source). You can get the project here:
http://wildermuth.com/downloads/xboxbrowser.zip
What do you think about Microsoft's new Phone OS and development platform?