If you installed the Silverlight Client for Facebook, and also upgraded to the release candidate for Silverlight 4, you may have noticed it stopped working :-).

NOTE: Applications compiled on Silverlight 4 beta will not work on machines with Silverlight RC runtime.  This is known/expected.  As with all pre-release software, this type of breaking can be expected.

We’ve recently updated the Facebook application, and you will have to re-install.  Follow these steps:

  1. Uninstall the Silverlight Facebook client.  You can do this in a few ways.  First on Windows through the Add/Remove Programs or by right-clicking on the application while it is running (even though it doesn’t work) and choose ‘Remove Application’ – I recommend the Add/Remove Program control panel option.  On Mac OSX, simply move the application to the trash.
  2. Ensure you have Silverlight 4 RC installed.  If you don’t the Facebook client welcome page will provide the links.  Reminder that this is still pre-release software and future uninstalls might be required.
  3. Visit http://bit.ly/facebookclient and follow the instructions.

You should now have the updated Silverlight for Facebook application installed.  The team received a lot of good feedback they look at.  This build doesn’t necessarily have any of those suggestions/fixes…and is more of a compatible build for the Silverlight RC runtime.  There are a few things that we finally brought forward from the initial PDC09 demonstration.

Custom Window options are clearly visible.  You’ll notice the ‘window chrome’ (as it is referred to) is gone and the custom window is in the application:

Silverlight Client for Facebook

Notice the custom maximize, minimize and close buttons:

Custom window chrome toolbar

Also notice in the lower right corner the resize adorner:

Resize adorner

The updated application also implements the ‘mini-mode’ (from the toolbar area in the upper right) which produces a stripped down view of the main news feed:

Facebook Client mini-mode

Again this is a subtle update to keep the client working for you.  These features use the custom window options available to Silverlight 4 developers.  You can read about this updated feature here and also watch a developer video tutorial on how to implement similar functions in your application here.

Have fun on Facebook and hope this helps!

One of the announcements that happened during the MIX10 conference was the availability of the V2 of the Microsoft Translator API.  This is the engine that powers the translation behind http://www.bing.com/translate and some other Bing-related properties as well.  A lot of research has gone into the engine from Microsoft Research and others.  Language translation isn’t an easy task especially taking into consideration cultural significance of words, etc.  I have heard that the most challenging in machine translation is to Asian languages.  I will admit to not speaking any of them, so I don’t know how well we are performing here – you’ll have to let that team know if they are doing well.

After reading the announcement and working on my translate plugin for the new Seesmic Desktop Platform, I noticed that there was a Speak API.  After reading I saw this literally translates text to a WAV file for platback.  Pretty cool I thought.  I wanted to play around with this in Silverlight so created a simple application to do so:

Microsoft Translator in Silverlight

The Speak translation isn’t available for all the Translator languages (currently 30 languages for text language translation) but does support seven (7) languages: English, German, Spanish, French, Italian, Portuguese, and Russian.  So how is Silverlight talking back to you?

The Translator API comes in 3 flavors: SOAP, HTTP and Ajax.  Now I could have used the SOAP version and used Add Service Reference but I felt for what I was doing this was overkill.  The SOAP API doesn’t return me back super-strongly typed objects, so I saw little value in doing that over the REST-based HTTP methods which I decided to use.  The code is relatively simple.  I first want to translate the text input into the selected language, then pass the translated text to the Speak API and play the results in a MediaElement.

First, we use the Translate method and a WebClient call to accomplish this:

   1: private void TranslateTextToAudio(object sender, RoutedEventArgs e)
   2: {
   3:     if (Languages.SelectedIndex < 0)
   4:     {
   5:         MessageBox.Show("Please select a language first...");
   6:         return;
   7:     }
   8:     WebClient client = new WebClient();
   9:     client.OpenReadCompleted += ((s, args) =>
  10:         {
  11:             if (args.Error == null)
  12:             {
  13:                 DataContractSerializer des = new DataContractSerializer(typeof(string));
  14:                 string responseText = des.ReadObject(args.Result) as string;
  15:                 SpeakIt(responseText);
  16:             }
  17:         });
  18:     client.OpenReadAsync(new Uri(string.Format(TRANSLATE_URI, _appId, HttpUtility.UrlEncode(TextToTranslate.Text), Languages.SelectedValue.ToString(), _currentLang)));
  19: }

Notice the DataContractSerializer use here.  The HTTP API returns serialized objects, so you’ll want to use this method here to deserialize to make it easier.

After we have the translated text, we pass that to the Speak API (notice the call to SpeakIt above) which returns a Stream that is an audio/wav format.   We know that Silverlight’s MediaElement cannot directly play lossless WAV format.  But luckily there is a MediaStreamSource API that enables us to essentially write our own decoders for audio/video.  One of the Silverlight team members, Gilles, created a WAV MediaStreamSource for us to use.  After having that and not worrying about decoding, I could create a new WaveMediaStreamSource with my result Stream and set that as the Source for the MediaElement – here is the resulting SpeakIt() method (TranslatedPlayback is the name of my MediaElement in the application):

   1: private void SpeakIt(string responseText)
   2: {
   3:     WebClient client = new WebClient();
   4:     client.OpenReadCompleted += ((s, args) =>
   5:     {
   6:         if (args.Error == null)
   7:         {
   8:             WaveMediaStreamSource mss = new WaveMediaStreamSource(args.Result);
   9:             TranslatedPlayback.SetSource(mss);
  10:         }
  11:     });
  12:     client.OpenReadAsync(new Uri(string.Format(SPEAK_URI, _appId, responseText, Languages.SelectedValue)));
  13: }

That’s it!  It’s pretty cool (bonus points to you in identifying the obvious pre-filled text being used in my sample).

I’ve almost completed my Seesmic plugin and using the Translator API has made it easier.  I’ve found that a simple wrapper to the HTTP-based methods is going to make things easier for people to use, so I’ve created a Translator Client for Silverlight that I’ll be releasing once I can complete the plugin (waiting on a few things).  This will make it easier for Silverlight developers to quickly consume the API for text and Speech translation.

The code (C#) for the above sample is here: MSTranslatorSilverlightSample.zip.  You will need a Translator Application ID key to run it yourself (put it in the App.xaml resources).  If you just want to see it running really quick, you can view it here: Speak Translator for Silverlight.  You will need Silverlight 4 RC to run the sample.

NOTE: The Translator API actually doesn’t need Silverlight 4, but I just created the app using that base.

Hope this helps!

If you’ve been excited about Windows Phone 7 development and the platform being Silverlight for application development, you probably rushed and downloaded all the tools (which are free by the way).  You may have even got the samples from the SDK and noticed the Location services example…but wondered why it doesn’t work.

If you are just getting started, I created some quickstart videos to help you through some of the basics.  You can view them here.

In case you haven’t figured it out: Location services (aka, GPS) is not emulated in the developer tools CTP. 

As you might expect, this makes it difficult to play around with location-based applications.

The API in Windows Phone 7 revolves around the GeoCoordinateWatcher class.  This class is what you would initialize to start listening for events:

   1: GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Low);
   2: watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
   3: watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);

As you can see, this watcher class looks for Status and Position changes.  The status is about the device peripheral itself (initializing, reading, etc.).  Position is more likely what you are interested in and would give you the details of where the device is reading the current location (longitude and latitude).  In the emulator right now the status will always return Disabled.

It’s relatively simple to simulate this, and here’s a really simple mock class for doing so.  Now, note this is not a complete emulation of the Location services APIs for Windows Phone 7 SDK.  This mock is to simply simulate a coordinate location and position changing.  The GeoLocationMock class implements the IGeoPositionWatcher<GeoCordinate> interface for mocking the location service.  There is a Start, Stop, PositionChanged and StatusChanged methods and events (TryStart is implemented, but simply calls Start).  To implement the mock in your application you would instantiate watcher (using above sample) as IGeoPositionWatcher<GeoCoordinate> instead of the GeoCoordinateWatcher specifically.  Here is a sample, and then an explanation:

   1: public partial class MainPage : PhoneApplicationPage
   2: {
   3:     IGeoPositionWatcher<GeoCoordinate> watcher;
   4: }
   5:  
   6: private void StartLocationService(GeoPositionAccuracy accuracy)
   7: {
   8:     if (watcher == null)
   9:     {
  10:         GeoCoordinateEventMock[] events = new GeoCoordinateEventMock[] {
  11:             new  GeoCoordinateEventMock { Latitude=34.4, Longitude=11.2, Time=new TimeSpan(0,0,5) },
  12:             new  GeoCoordinateEventMock { Latitude=31.4, Longitude=21.2, Time=new TimeSpan(0,0,1) },
  13:             new  GeoCoordinateEventMock { Latitude=34.3, Longitude=28.2, Time=new TimeSpan(0,0,2) },
  14:             new  GeoCoordinateEventMock { Latitude=32.4, Longitude=34.2, Time=new TimeSpan(0,0,3) },
  15:             new  GeoCoordinateEventMock { Latitude=31.2, Longitude=37.2, Time=new TimeSpan(0,0,4) },
  16:             new  GeoCoordinateEventMock { Latitude=33.73, Longitude=39.2, Time=new TimeSpan(0,0,5) },
  17:             new  GeoCoordinateEventMock { Latitude=31.87, Longitude=41.2, Time=new TimeSpan(0,0,6) },
  18:             new  GeoCoordinateEventMock { Latitude=11.81, Longitude=42.2, Time=new TimeSpan(0,0,7) }
  19:         };
  20:     
  21:         watcher = new EventListGeoLocationMock(events);
  22:         watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
  23:         watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
  24:     }
  25:  
  26:     watcher.Start();
  27: }

The ‘watcher’ is created using a list of geo location points in this sample above.  Now this could be some web service that does IP address reverse lookup or use hard-coded examples as well like I’ve done above.  Using this mock above and replacing it in the LocationServiceSample in the SDK, here’s what my screenshot shows:

Geo location services mock for Windows Phone 7

So you can see I can start the GPS emulation and simulate subtle position changes (or drastic ones if I wanted, aka maybe a social network map application of sorts).

Hopefully this little snippet will be valuable to play around with or expand upon for your needs.  If anything, you can create some emulation of the behavior temporarily.  The mock object used in a modified LocationServiceSample project can be downloaded here: LocationServiceSampleWithMock.zip.

Hope this helps!

UPDATE: Peter Torr actually had another geo location mock in his MIX10 talk which his code is now available for download.  It is much more comprehensive emulating accuracy, etc.  The above is a simpler approach, but both will get the job done depending on what you really need/want to emulate.


This work is licensed under a Creative Commons Attribution By license.

So the news is out! 

Silverlight IS the platform for Windows Phone 7 Series development!

Sweet.  We also made available an update to Silverlight 4 that you might be interested in too!

Windows Phone 7 SeriesYou may be wondering how you get started.  If you are new to Silverlight, I recommend getting familiar with Silverlight first.  You can find all the tools you will need at the Silverlight community site.  In addition to the core tools you’ll want to get the Windows Phone Developer Tools CTP.  This will add to your Visual Studio 2010 installation (or install Visual Studio Express) to enable Windows Phone and XNA Game Studio development.  Be sure to read the documentation on the release notes to understand any limitations.  A link to the tools, documentation, developer/UX guides and more can be found on the Silverlight for Windows Phone page.  The key elements you’d want to get  are:

I’ve also taken some quick time to get some quick videos up for some tips and familiarity with the tools and some initial areas you’ll want to take a look at.  Here are some starting videos for you:

The getting started video has some quick tips and tricks about the emulator and using the keyboard input control (referred to as the ‘SIP’).  I suggest taking a look at these for some primer.  If you have questions afterwards, check out the dedicated forum for Silverlight for Windows Phone.

I’m looking forward to seeing what you’ll develop using Silverlight for Windows Phone!  Be sure also to watch for @ckindel and @wp7dev on Twitter for information about Windows Phone 7 Series development.



This work is licensed under a Creative Commons Attribution By license.

UPDATE: Silverlight 4 is RELEASED!  READ HERE!

Silverlight 4At MIX10, Silverlight 4 released an update, the Silverlight 4 RC (release candidate).  A few things have changed since the beta which was released in November.  If you haven’t read my guide to Silverlight 4 you may want to check that out.  The features still exist, but there are some changes to the implementations of some of the features as well as some new ones.  Please go read the previous post to familiarize yourself with the features.  This post will be complimentary to that and identify new/changed.

First let’s get you going with the tools:

And since sometimes people just want to get going with learning resources here’s my top suggestions:

So here we go, here’s my brain dump of some key areas of what you’ll be seeing in the Silverlight 4 RC.  This is not all-inclusive, but I think a list of some that most will want to know about.

ChangedNew

A quick note about Visual Studio 2010 RC

The Silverlight 4 tools linked above target the RC release of Visual Studio.  There have been 2 patches to Visual Studio 2010 RC since it’s release.  It is recommended that you have these two patches installed prior to installing the Silverlight tools.  Information about these patches (and links to them) is available here.

RichTextBox (the control formerly known as RichTextArea)

Silverlight 4 introduced a new control for enabling editing and display of rich text.  (See original details here for RichTextArea.)  A few things have changed here, one key one being the name: RichTextBox.  This was to be more consistent with WPF and also based on your feedback.  Additional improvements were also enabling the ability to get the XAML that makes up the underlying runs and paragraph of the rich text.  This is helpful for saving off the data and re-hydrating later if desired.  It’s a simple property on the RichTextBox control (assuming the control name is ‘MyRichContent’):

   1: string richText = MyRichContent.Xaml;

In addition to that, there are also some new text selection and position APIs to enable you programmatically select text and/or know where the current position of the text is located.  This is best demonstrated in the ‘Silverlight Notepad’ sample application in the hands-on-lab area where you can see examples of it being used.

^ back to top

WebBrowser control

The beta provided us with a mechanism for hosting HTML content within an out-of-browser application.  This is still available to us, however some APIs have changed.  The HtmlBrush is now called the WebBrowserBrush to be consistent in naming and what it actually does.

You can view a video on using the WebBrowser control here.

^ back to top

Printing API enhancements

The printing API was enhanced to help developers query for the printer page size and the printable area.  Another change was where the ‘document name’ is provided.  It is now required and a part of the Print() method.  Before:

   1: PrintDocument doc = new PrintDocument();
   2: doc.DocumentName = "Sample Document";
   3: doc.Print();

After:

   1: PrintDocument doc = new PrintDocument();
   2: doc.Print("Sample Document");

You can view a video on using the printing APIs here.

^ back to top

Native automation (COM interop)

API changes in the naming of the native integration (COM interop) feature for trusted applications.  Before:

   1: dynamic excel = ComAutomationFactory.CreateObject("Excel.Application");

After:

   1: dynamic excel = AutomationFactory.CreateObject("Excel.Application");

Simple, but will catch you in a recompile :-).  You can view a video on using native integration here.

^ back to top

Language/script support

Silverlight now has extended language support, including Thai and Vietnamese.  Additionally we added support for multiple Indic scripts.  The following Indic scripts are now supported:

ScriptLanguage
BengaliBengali, Assamese, Manipuri
OriyaOriya
MalayalamMalayalam
KannadaKannada
TamilTamil
TeluguTelugu
GujaratiGujarati
GurmukhiPunjabi
DevanagariHindi, Marathi, Sanskirt, Konkani, Kashmiri, Nepali, Sindhi

^ back to top

Networking

In the beta, socket ports were still being restricted in trusted applications.  In this release, the port restriction for socket ranges in trusted applications is removed.

Additionally, the client networking stack (ClientHttp) has been enhanced to enable UploadProgress reporting and caching support.

^ back to top

User consent dialogs (webcam/clipboard/etc.)

We call those dialogs that require user permissions ‘consent dialogs.’  Your users will see these whenever code requires things like requesting device access for webcam/microphone, clipboard access, or quota increase for IsolatedStorage.  In the beta we showed these dialogs always and didn’t have a mechanism for enabling the user to determine if they wanted their consent preference saved.  That has changed in this release.  Consent dialogs now give the user the option to remember the setting which is persisted to their preferences only for that application and is in their control.  Here’s the new consent dialog for clipboard, webcam and full-screen pinning:

Silverlight consent dialog

And if you look at the Silverlight configuration dialog you’ll notice a permissions tab now where these permissions are set for the user, which they can change or delete:

Silverlight permissions dialog

This consent dialog ‘remember my preference’ setting is not available for IsolatedStorage quote increase however.  It doesn’t make sense to enable that really for that scenario.

^ back to top

XAP Signing for trusted applications

We think trusted applications (or elevated privileges applications) will be a widely used feature for this release.  We changed the install prompt dialog for trusted applications.  These are different dialogs than the typical out-of-browser install prompt as we need the user to have more information provided about them.  One key feature of a trusted application is the ability to code-sign the XAP file.  Here’s a trusted application install prompt from an un-signed application:

Windows:

Unsigned trusted application on Windows

Mac OSX:

Unsigned trusted application on OSX

And here is one from a code-signed one:

Windows:

Signed trusted application on Windows

Mac OSX:

Signed trusted application on OSX

Which would you feel more comfortable installing?  Notice that in signed applications your custom icon will show as well (even if you have the icon settings set up, if the app is unsigned they will not show).  The process of code signing is very simple and although I expect the tooling for Silverlight to improve on this, it is as simple as adding a post-build event task (or a task for automated builds) that uses the signtool.exe (installed with Visual Studio) to sign the XAP.  Here’s my post-build event task:

   1: "%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe" sign /v 
   2:     /f c:\users\timheuer\documents\authenticode\timheuer.pfx 
   3:     /p "MYPASSWORD" 
   4:     /t TIMESTAMP_URI_FROM_PROVIDER $(TargetName).xap

The PFX file is an exported certificate with my private key and password protected.  You can acquire code-signing certificates (normal Authenticode ones) from providers.  We were thankful to get assistance in testing this feature from the following providers who can provide you code-signing certificates for your organization:

All of the above provide Authenticode code-signing certificates and are trusted certificate authorities (CA) on Windows.  A trusted CA means that their root certificates are already a part of Windows verification.  The process of obtaining one is not instant so plan ahead.  There is a specific organizational verification process that occurs which may require documentation of proof of the organization and a few phone calls.  Once you have these certificates you will be on your way to providing even more trusted applications to your users.

NOTE: Thawte code-signing certificate requests should be made from a Windows XP machine as their current process does not support Windows Vista or Windows 7.  If you use Vista/7 you will not be able to export to a PFX file for automated build or to have your certificate stored on other machines.  Read each instructions carefully.

You can also sign your XAP using self-signed certificates.  If you do so, it is likely that you are not a trusted CA on machines and would have to instruct your users further.  In my opinion, it is better to acquire a trusted CA cert for external applications.  Take a look at Jeff Wilcox’s epic post on Code Signing 101.

A special note on trusted applications…please read!  If you want to take advantage of using the update features of Silverlight for your application (aka CheckAndDownloadUpdateAsync), then your application must be signedIf you do not sign your XAP for a trusted application it cannot auto-update.  Self-signed works here to, but don’t get your application in a state where it cannot be updated automatically!

You can view a video walk-through of XAP signing here.

^ back to top

Custom window chrome

One of the more requested features of trusted applications is the ability to customize the ‘chrome’ around the window.  The chrome area refers to the standard OS-specific border and title bar that a typical out-of-browser application will receive.  In this release we give you the ability to customize this for your users.  The Visual Studio tools also build in the capability to make this easier for you:

Window Style setting options

You can see there are a few options to choose from for window types.  Right now we do not support transparent windows or irregular shapes but are aware of the desire to have these.  Here’s an example of the Facebook client before:

Silverlight Facebook Client (beta)

and with custom window chrome:

Silverlight Facebook Client custom window

You’ll notice that in the custom window mode that since you don’t have the OS-specific title bar with minimize/maximize/close that you’ll be responsible for doing that.  That also includes handling the window moving and resizing events.  We enable APIs for you to do all of this easily. 

You can view a video on customizing window chrome and handling resizing and moving here.

^ back to top

Pinned full-screen mode

Are you a developer with multiple monitor setup?  I’m jealous.  If you’ve used silverlight you’ve no doubt run into a situation where you’ve put something in full-screen on one monitor and anticipated being able to work on other stuff in the other monitor.  Maybe you’re watching a Netflix movie while working?  You’ve likely experienced the issue that the full-screen mode goes back to regular when activity occurs in the second monitor.

We’ve changed that to enable the developer to prompt for permission to 'pin’ the Silverlight application to the monitor.  This will prompt the consent dialog option (with preference remembering) to get the user’s permission.  The code is extremely simple:

   1: App.Current.Host.Content.FullScreenOptions = System.Windows.Interop.FullScreenOptions.StaysFullScreenWhenUnfocused;

Once that is implemented, the full-screen application will remain pinned until the user hits ESC key or until you change the IsFullScreen mode in the code for them.

You can view a video on using the full-screen pinning mode here.

^ back to top

ContextMenu control

In the beta we introduced the right-click event handling capabilities.  In most cases this would be used by developers to implement context menus.  The Silverlight Toolkit for March 2010 release now provides a ContextMenu control for you to use and wire-up for this event.  It’s similar to the one Jesse Bishop created for the beta, so if you’ve used that it should be familiar.  It also supports ICommand too!

You can get the ContextMenu control and other great controls by ensuring you download and install the Silverlight Toolkit March 2010 release.

^ back to top

SLLauncher silent installs

One of the features we added in this release was using the sllauncher.exe (which is the program that assists in out-of-browser applications) to provide silent install capabilities for your applications.  The primary scenario here would be something like CD-based installation situations.  Using a command like this:

   1: "%ProgramFiles%\Microsoft Silverlight\sllauncher.exe"  
   2:     /install:"D:\deploy\demoapp.xap"  
   3:     /origin:"http://foocompany.com/apps/ClientBin/demoapp.xap"  
   4:     /shortcut:desktop+startmenu  
   5:     /overwrite 

would enable you to deploy an application in this type of a situation.  Setting the origin flag here enables the application to determine where it would get future updates from if CheckAndDownloadUpdateAsync methods are called within the application.

^ back to top

WCF RIA Services Toolkit

If you read above you’ll know that installing the Silverlight 4 Tools for Visual Studio also automatically installs the WCF RIA Services framework for you.  This release the RIA Services team also has a toolkit of their own.  After installing the RIA Services Toolkit you’ll get:

  • LinqToSql DomainService
  • SOAP endpoint – enabling exposing a SOAP endpoint for your DomainService
  • JSON endpoint – enabling exposing a JSON endpoint for your DomainService
  • ASP.NET DomainDataSource – enabling your ASP.NET application to talk to your DomainService

This is a separate install that you must complete.  For more details on this toolkit, visit Deepesh’s blog.

If you aren’t familiar with WCF RIA Services, you can view an introductory video here.

^ back to top

Summary

It’s been a fast pace since getting the Silverlight 4 beta in your hands in November.  We’ve had a lot of work to do to finish things up and implement some new key features.  We are very excited about this release of Silverlight 4 for developers and look forward to seeing the great applications you build with it!

Be sure to visit the MIX10 site for video recordings of various Silverlight-related presentations as the event is happening and as reference later on!  I really encourage you to view the keynote to see some new consumer-facing application experiences built on Silverlight, like eBay, Associated Press (Windows Phone 7)

Hope this helps!  Be sure to subscribe here via RSS or email and if you’re on Twitter you can follow me there as well for Silverlight updates/resources


This work is licensed under a Creative Commons Attribution By license.