Friday, July 10, 2009

Silverlight 3 SaveAs Dialog debugging quirk

I have been playing with the new SaveAs dialog in Silverlight 3 and discovered an odd quirk. While debugging I was getting the following exception:

System.Security.SecurityException was unhandled by user code

Message="Dialogs must be user-initiated."

From all appearances, my SaveAs dialog was being initiated from a user-initiated event. The code to open the dialog was being executed in the Click event handler of a button on my Silverlight control. The problem was... I had a breakpoint set on the line of code that performed the ShowDialog(). Once I moved the breakpoint to the next line of code everything worked.

Hope this helps anyone banging their head against the wall on this one...

(BTW...thanks Silverlight team... this was a much needed control.)

Labels: ,

Friday, April 10, 2009

Silverlight MVVM and the Silverlight Unit Test Framework

I have been working diligently the last few months on trying to integrate better test coverage into my Silverlight development.

After scouring the web and absorbing a lot of good information on Silverlight Unit Testing from posts such as these:
And integrating the Model-View-ViewModel (MVVM) presentation pattern outlined in these great posts:

I feel I have finally put together a nice example of a Silverlight control that utilizing the Microsoft Silverlight Unit Test Framework.

My example is a straight forward Login control. I think login controls make for great demo applications. They are probably only one degree of difficulty above the traditional "Hello World" example. In it's simpilest form a login control only contains two input text boxes, a button and a text message area to display feedback. This example throws in a touch of animation, because after all, it is a Silverlight application :)


You can download the code here.

Labels: , ,

Tuesday, October 7, 2008

Silverlight Styles are Immutable

Ever see this friendly message in Silverlight?

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

Well, one thing you might want to check is if you are setting the Style on a control more than once. Seems that Styles are immutable in Silverlight 2.0 and therefore cannot be set more than once.

Labels: ,

Friday, August 15, 2008

Embeding Silverlight control in web page OBJECT versus EMBED

When deploying a Silverlight control on a web page, there are several options available. You can either use the asp:Silverlight control or embed the control into your HTML using either the OBJECT or EMBED HTML tags.

One interesting gotcha that I ran into was when I tried to instantiate the Silverlight plug-in using the OBJECT tag in Firefox 3.0. The plug-in would just not load, which is strange, because before I updateded to Silverlight Beta 2 everything seemed to work fine. After poking around, I found that Apple's Safari web browser doesn't currently support the OBJECT element. Instead you have to use the EMBED tag, which works equally well in IE and Firefox. Perhaphs Microsoft is playing to the lowest common denomentor in an attempt to keep Silverlight 100% cross-browser compliant?

Either way, if you use the EMBED tag to instantiate the Silverlight plug-in, there are a couple of things to take note of:
  1. Custom parameters that are defined as individual
  2. Alternative content that displays when the Silverlight plug-in is missing will need to be wrapped in a NOEMBED element.
Here are 2 seperate implementations of a Silverlight control. One using OBJECT tag and the other using the more compliant EMBED tag.

OBJECT Implementation

<object type="application/x-silverlight" id="silverlightControl" width="390" height="100">
<param name="background" value="Yellow">
<param name="source" value="Chapter1.xaml">
<!-- Alternative content: -->
This content requires Silverlight.
<a href="http://www.microsoft.com/silverlight/downloads.aspx">
Get it Here.</a>
</object>

EMBED Implementation

<embed type="application/x-silverlight" id="silverlightControl" width="390" height="100" background="Yellow" source="Chapter1.xaml">
<noembed>
<!-- Alternative content: -->
This content requires Silverlight.
<a href="http://www.microsoft.com/silverlight/downloads.aspx">Get it here.</a>
</noembed>
</embed>

Labels:

Thursday, May 22, 2008

Silverlight 2.0 - Savior of the Internet or latest fad?

Recently I had the opportunity to build a control for SnagAJob.com in Silverlight 2.0. My first impression is...Wow!... This is going to change a lot of things.

I think it is important to mention that I am coming to Silverlight development late. I never played with the 1.0 or 1.1 releases. I never had to go through the early pains of discovery associated with the technology. (ahh...remember the early days of the AJAX Toolkit). First off, I want to give a big "hats-off" to the team over at Silverlight.Net. If you have not been to the site, you are definitely missing out. The Getting Started section is the perfect place to well.... get started. They also have a fabulous set of video tutorials and gallery samples (many with code) to get you up and running on Silverlight.

If you are new to Silverlight, developing in Silverlight 2.0 with managed code is very intuitive, especially if you have any prior experience with Windows Forms development. An easy way to think about the design paradigm is that of a Windows Form application running in the browser. BUT... it is so much more... It is Flash like in nature in that it runs as an embedded control in your page. You simply have to install the Silverlight runtime. Hopefully Microsoft will begin pushing out the runtime as part of it's Windows Update.

Could Silverlight be the death of AJAX? Silverlight is based upon a subset of WPF. The ability to develop web content using XAML will truly open up the Internet to a host of creative and visually stunning applications. The problem I see with AJAX is that it still requires the mixing of technologies. (HTML, JavaScript, Services). While Silverlight 2.0 doesn't completely eliminate the technology mash-up, I believe the unified development environment (XAML, Managed Code)that Silverlight 2.0 provides will super charge the development of visually attractive and highly interactive user experiences.

Could Silverlight be the death of ClickOnce? In some circumstances it might. It provides the end-user experience required by many applications that are currently written as Windows Forms applications and it's deployment scenario is possibly simpler than that of ClickOnce. To deploy a Silverlight application, you only need to copy the latest-n-greatest bundled version of your control (.xap file) up to your web server. Silverlight is cross-browser compliant, so the headaches of ClickOnce deployment for end-users running Firefox is avoided.

Silverlight is obviously not a silver-bullet. There are plenty of short comings that will need to be overcome, but I believe there are good things in store for this technology.

My friend and colleague Kevin Hazzard has been doing some great presentations and code camps lately on Silverlight. Check out his GotNet blog for some great reading.

Labels: , , , ,