Rants Tagged with “Silverlight 2”
For the last few iterations of Silverlight 2 I've been keeping some data-driven examples on my sister site: www.silverlightdata.com. Since Silverlight 2 was released I've been working on a more comprehensive example using ADO.NET Data Services, NHibernate, Entity Framework and Forms-based Authentication. its taking longer than I'd like but when its live, I'll post about it here. I've taken down the old samples since they haven't been refactored to work with the new bits.
Sorry for the confusion...
If you are thinking about using SQL Data Services (the data part of the Azure stack) in your Silverlight 2 project, think again. As you might know, ADO.NET Data Services (Astoria) will not work cross-domain regardless of a security policy file (because of some limitations in the two networking stacks that Silverlight 2 uses). Its a problem but in most use-cases ADO.NET Data Services (Astoria) is used on the same domain so no biggie...but...
The Azure SQL Data Service uses Astoria to expose their data to the client...that means that with the ADO.NET Client Library that you can't access SQL Data Services. The reality is that since SQL Data Services requires basic authentication, it would not be terribly secure to call it in any case but this seals the deal.
The only good news is that since Astoria is just REST, you might be able to do the work to call it manually using WebClient or HttpWebRequest but its not an easy fix.
Too bad too, it would have been a great mix...SL2 + SDS.
Announced yesterday on Jeff Wilcox's blog, the new drop of the Silverlight 2 Testing Framework is now available. The framework can be used to create unit tests for the Silverlight 2 application as well as do UI testing.
Go get it now and stop releasing Silverlight 2 apps you never bothered to test...you no longer have an excuse...
Announced today and the PDC and now publically available is a new project from Microsoft called the Silverlight 2 Toolkit. This toolkit contains new controls for Silverlight 2. The controls are available on CodePlex which means it is open source. The controls are being built by Shawn Burke's team inside Microsoft and have several "quality bands". These bands are "Experimental", "Preview", "Stable" and "Mature". This allows you to see what they're working on and determine which ones to use. The available controls are:
Stable band:
- DockPanel
- HeaderedContentControl
- HeaderedItemsControl
- Label
- TreeView
- WrapPanel
Preview band:
- AutoCompleteBox
- ButtonSpinner
- Charting
- Expander
- ImplicitStyleManager
- NumericUpDown
- Spinner
- UpDownBase
- Viewbox
No controls are Experimental or Mature yet. The inclusion of the TreeView and WrapPanel are of most interest to me as building these controls manually are particularly difficult.
In addition to the controls, this package includes several built-in styles for skinning your application (using the ImplicitStyleManager). These styles include:
Go grab the package and start playing! Don't forget to post bugs if you find them.
Interesting news from Netflix that they are going to be using Silverlight to stream movies to Macs to support their "watch instantly" service. They had left the Mac and Linux guys in the lurch for a while but its just fantastic that the Mac guys (and perhaps Linux with Moonlight?) will get the service. I suspect this is an extension of the XBox 360 deal. I wonder if this means that the streaming on the XBox is Silverlight 2 based?
Is this cool or not?
While in Bulgaria I had time to sit down with Carl Franklin and do an episode of DNRTV. I am happy to annouce its now live. I built a simple data-driven application using Silverlight 2 with Blend 2 and Visual Studio. This screencast should some basic techniques of separation of UI and Data in Silverlight that will help you do your data binding directly in Blend 2 SP1. If you haven't seen how this works, go grab the Screencast now!
Here is a quick but fun tip for working with Silverlight 2. I found that many people are using Isolated Storage for saving user preferences or other small pieces of information. When I look at the code, I am surprised by how much trouble they are going through to save small bits of data. That's where Isolated Storage Settings come in.
For example, let's assume you want to be able to store a FavoriteColor for a user. You could cruft up a bunch of code to save a file and handle the serialization, or you could use the IsolatedStorageSetting class. This class supports being able to store arbitrary objects in a settings file in Isolated Storage. The IsolatedStorageSettings class supports two keyed collections, ApplicationSettings and SiteSettings. ApplicationsSettings is specific to your .xap file, while SiteSettings are specific to your domain. Here is an example of a property that uses the IsolatedStorageSettings to store a nullable Color for FavoriteColor:
const string FAVCOLORNAME = "favoriteColor";
public Color? FavoriteColor
{
get
{
if (IsolatedStorageSettings.ApplicationSettings[FAVCOLORNAME] != null)
{
Color? colorSetting = IsolatedStorageSettings.ApplicationSettings[FAVCOLORNAME] as Color?;
if (colorSetting != null) return colorSetting;
}
// If we can't find a favorite color, return a null color
return new Color?();
}
set
{
IsolatedStorageSettings.ApplicationSettings[FAVCOLORNAME] = value;
}
}
If you are familiar with ASP.NET, you'll probably see that the pattern here is similar to Cache or Session data. The idea is the same. You should always code this defensively as Isolated Storage maybe cleared or could be disabled by the user. In addition, you should be careful *not* to store sensitive data as the user can get access to files in Isolated Storage (though its hidden in a deep directory structure). So avoid saving sensitive data like connection strings or other sensitive information that you want to keep from the user.
HTH
There is still time to register if you want to join me in Atlanta for the first Silverlight 2 Release workshop. I will be guiding the students through the maze of skills required for Silverlight 2 including XAML, Blend, Visual Studio 2008, Web Services, ADO.NET Data Services and even advanced topics like control customization and line-of-business application development.
If you're intersted in the class, please register through http://silverlight-tour.com.
Not a biggie, but just so that anyone that reads my blog knows...its "Silverlight 2", not "Silverlight 2.0". Wasn't my decision, but its the fact. Journalists and bloggers alike have been throwing out "2.0" a lot lately and after being hammered by some well-meaning Microsofties about the name, I just wanted to make sure everyone knows the right way.
'Nuff about that...
In meeting with a client (Schoolmaster.nl who is building a cool LOB app), we came across the problem of one of their components was throwing Image Failed Javascript errors. Handling them in the App.UnhandledException event didn't help because the errors were surfaced outside the plug-in, directly to Javascript. Immediately I use the VisualTreeHelper to walk the entire XAML tree (including nested templates) to just add an event handler on to every ImageFailed events to try and suppress these errors.
public Page()
{
InitializeComponent();
Loaded += (s, e) =>
{ // Call Recursive method to wire all Image tags
WireImageFailed(this);
};
}
void WireImageFailed(DependencyObject source)
{
for (int x = 0; x < VisualTreeHelper.GetChildrenCount(source); ++x)
{
DependencyObject child = VisualTreeHelper.GetChild(source, x);
if (child is Image)
{
((Image)child).ImageFailed += (s,e)=>
{
// NOOP
};
}
WireImageFailed(child);
}
}
In case you're not familiar with this class, it helps you walk through the entire render tree at runtime (including inside controls and control templates). This means I could look for all the Image objects and handle the event to suppress the error. This worked but it felt hacky and doesn't work for them as they are building a lot of dynamic XAML.
After digging further, I found out that for compatibility with Silverlight 1.0, they are actually thrown at the Plug-in level so if you want to suppress them, just handle the OnError on the plugin. You can do this no matter how you are hosting the plugin:
<!-- ASP.NET Silverlight Control -->
<asp:Silverlight ID="Xaml1"
runat="server"
Source="~/ClientBin/BadImageTest.xap"
MinimumVersion="2.0.31005.0"
Width="100%"
Height="100%"
OnPluginError="SLPluginError" />
<!-- OBJECT Tag -->
<object data="data:application/x-silverlight-2,"
type="application/x-silverlight-2"
width="100%"
height="100%">
<param name="source"
value="ClientBin/BadImageTest.xap"/>
<param name="minRuntimeVersion"
value="2.0.31005.0" />
<param name="onerror"
value="SLPluginError" />
</object>
By handling the plugin error, we can either do something about it or just ignore the image/media errors:
function SLPluginError(sender, args) {
// NOOP
}
Its not elegant, but if you want to stop those annoying script errors from the plug-in, this is the way. At least until I get Microsoft to agree that this isn't a valid way to handle it.