Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Welcoming Silverlight 3 RTW

DZone's Guide to

Welcoming Silverlight 3 RTW

· ·
Free Resource
As of today, Silverlight 3 has officially released. My congratulations again to the Silverlight and Expression teams for the great job they did in getting some great products out on a relatively short timeline.

Breaking Changes and Quirks Mode

Be sure to read the breaking changes document that is included with the Silverlight 3 development tools. This will help clear up any confusion about why things aren’t working the same way they were in the beta.

Note that, unless the Silverlight team made a mistake, your Silverlight 2 apps will all run on Silverlight 3 SL Storkwithout compiling. The team built in a quirks mode to handle breaking changes from Silverlight 2 to Silverlight 3. So, if your app was compiled against Silverlight 2, and not recompiled on Silverlight 3, it will run in quirks mode and run just like it did on Silverlight 2. If you recompile under Silverlight 3, you’ll potentially see some breaking changes. There’s more info on this in the document.

Updated Out of Browser Support

One of the larger changes from the Silverlight 3 beta is the way that out of browser support is handled. You can now set the size of the window, and have better control over the experience. The application can correctly identify if it is running in or out of browser, and if it has been installed locally or not. The changes are breaking changes from the beta, but definitely for the better.

The full out of browser chapter from my book will be on the manning site soon, so be sure to join the Manning Early Access Program to get that and other chapters as they pass editorial review and get released out to the web.

I think the chapter on binding, which includes a bunch of information on the new DataForm and how to create custom validators, has been my favorite chapter so far.

The book will also have information on the ViewModel pattern, how to test and debug Silverlight applications, how to build and use behaviors, and how to build business applications using the latest .NET RIA Services releases. I tried to make sure that I covered the gamut with a strong dual focus on the information required to build complex business applications through to smaller RIAs such as what may be needed on something like the PETA site we did, as well as an equally strong focus on the things that agencies and designers building web experiences will need to help make their experiences shine. While it is definitely a programmer’s Silverlight book, there’s a little something in there for everyone.

Anyway, here’s a small part of the OOB chapter, showing how to provide a different user experience when running out of browser vs. in-browser. In this case, I’m forcing the user to run OOB in order to get a meaningful UX. Proceed with caution before doing that in your own app – you should have very good reasons before you force a user to do anything

Silverlight provides several useful APIs for both detaching your application from the browser and for checking the current state of your application. The first is the Application.Current.InstallState value. The values for InstallState are shown in table 4.8

Table 4.8 the various values of InstallState

State

Meaning

Installed

The application has been installed by the user. Note that the current instance of the application may still be running in-browser. This value only tells you it is available in locally installed mode for the current user/machine.

InstallFailed

The application tried to install, but failed.

Installing

The application is currently in the process of installing. This is a good place to download required assets if you intend to allow the application to run offline as well as out-of-browser.

NotInstalled

This value indicates that the application has not been locally installed.

When the installation state is changed, the Application object will raise an InstallStateChanged event which informs you to look at InstallState for the latest state.

You can extend this concept to force an out of browser-only mode in your application simply by refusing to display the application UI unless running out of browser. In that case, your in-browser application would simply be an "install me locally" splash screen. Let's run through a quick example showing that.

Listing 4.3 Forcing Out of Browser Mode

...
<Grid x:Name="IBNotInstalledExperience">
<Button x:Name="InstallButton"
Height="100"
Width="400"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Take Out of Browser" />
</Grid>

<Grid x:Name="IBInstalledExperience">
<Rectangle Fill="Azure"
Stroke="LightBlue"
RadiusX="10"
RadiusY="10"
Margin="20" />

<TextBlock Text="This application is installed locally. Please run from the shortcut."
FontSize="30"
Margin="30"
TextWrapping="Wrap"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>

<Grid x:Name="OobExperience"
Visibility="Collapsed">

<Rectangle Fill="Azure"
Stroke="LightBlue"
RadiusX="10"
RadiusY="10"
Margin="20" />

<TextBlock Text="Running out of browser"
FontSize="30"
Margin="30"
TextWrapping="Wrap"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
public MainPage()
{
InitializeComponent();

Loaded += new RoutedEventHandler(MainPage_Loaded);
InstallButton.Click += new RoutedEventHandler(InstClick);
Application.Current.InstallStateChanged +=
new EventHandler(OnInstallStateChanged);
}

private void UpdateUserInterface()
{
if (Application.Current.IsRunningOutOfBrowser)
{
OobExperience.Visibility = Visibility.Visible;
}
else
{
if (Application.Current.InstallState == InstallState.Installed)
{
IBInstalledExperience.Visibility = Visibility.Visible;
IBNotInstalledExperience.Visibility = Visibility.Collapsed;
OobExperience.Visibility = Visibility.Collapsed;
}
else
{
IBInstalledExperience.Visibility = Visibility.Collapsed;
IBNotInstalledExperience.Visibility = Visibility.Visible;
OobExperience.Visibility = Visibility.Collapsed;
}
}
}

void OnInstallStateChanged(object sender, EventArgs e)
{
UpdateUserInterface();
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
UpdateUserInterface();
}

void InstClick(object sender, RoutedEventArgs e)
{
Application.Current.Install();
}

The experiences resulting from the code in listing 4.3 are shown in figures 4.12. and 4.13. Note that the Install method may only be called from a user-generated UI event, such as a button click. This is to prevent applications from self-installing without explicit user intervention.

Figure 4.12 The experience a user will see if they have not installed this application. Clicking the button calls Application.Current.Install()

Figure 4.13 The same application after it has detected that it has been installed and is running out of browser. Note that the browser-hosted version responded to the InstallStateChanged event by changing its own UI.

So while you can't exactly force an application to install locally, you can design it to show different interfaces depending upon its installation state and current mode of operation. Think carefully before you use this type of code in your own applications; if there's no compelling reason to force an application to run out of browser only, don't force the user.

The next step in customizing the experience is to change the icons displayed in the install dialog, the application window, the start menu and the task bar. …


Where can I find the bits?

Your best location is always Silverlight.net Check out the updated Getting Started section for download links.

 

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}