15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1096 ❘ ChaPTer 38 silverliGht<br />

You can use Moonlight to run Silverlight applications on a Linux system. You can<br />

download Moonlight at http://www.gomono.com/moonlight. Check this page for the<br />

current status of supported features with Moonlight.<br />

When you compile a WPF application, you get an executable assembly that contains XAML code in a<br />

binary form, named BAML, as a resource. With a Silverlight application, the compiler creates an XAP fi le<br />

that is a ZIP package containing the assembly <strong>and</strong> confi guration.<br />

In the .<strong>NET</strong> Framework for Silverlight, you will fi nd the same classes as in the full .<strong>NET</strong> Framework but, of<br />

course, not all of them. Some classes are missing <strong>and</strong> also several methods <strong>and</strong> properties from classes that<br />

are available with Silverlight.<br />

What ’ s completely unavailable with Silverlight 3 that you have with WPF is support for fl ow <strong>and</strong> fi xed<br />

documents (see Chapter 37, “ Creating Documents with WPF ” ) <strong>and</strong> 3 - D (3 - D is covered in Chapter 35,<br />

“ Core WPF ” ). You can simulate 3 - D with 2 - D in Silverlight but, of course, this is completely different from<br />

the 3 - D functionality of WPF. Interoperability to Windows Forms is not available either. In any case, it ’ s<br />

better to write the UI new with XAML instead of integrating Windows Forms controls.<br />

There are also some smaller differences that can be frustrating if you write applications both for WPF <strong>and</strong><br />

Silverlight:<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

Mouse clicks <strong>and</strong> events — In Silverlight, the right mouse click is always caught by the browser<br />

<strong>and</strong> doesn ’ t get to the Silverlight control. That ’ s why there ’ s no right button down/up event. There ’ s<br />

also no double - click event. Silverlight doesn ’ t have events for the mouse wheel. When reading the<br />

properties of RoutedEventArgs , with Silverlight just the properties H<strong>and</strong>led <strong>and</strong> OriginalSource<br />

are used. This changes with Silverlight 4 with the right mouse click <strong>and</strong> mouse wheel support.<br />

Brushes — Silverlight doesn ’ t have the DrawingBrush , VisualBrush , <strong>and</strong> TileBrush brushes.<br />

However, you have the VideoBrush brush available to add videos to the brush.<br />

Fonts — Because not all the fonts are available on all platforms, Silverlight is limited in the fonts<br />

it offers.<br />

Controls — Silverlight doesn ’ t have Menu , Toolbar , Window , <strong>and</strong> WebBrowser controls. However,<br />

there are some controls that Silverlight has that are not available with WPF. Over time, these<br />

differences will disappear. Calendar , DatePicker , DataGrid controls fi rst appeared in Silverlight<br />

<strong>and</strong> are now available with WPF as well. AutoCompleteBox <strong>and</strong> NumericUpDown are controls that<br />

are currently missing from WPF.<br />

Networking — To avoid blocking the UI thread, only asynchronous calls are available. With<br />

Silverlight 3, you ’ re limited to the BasicHttpBinding <strong>and</strong> PollingDuplexHttpBinding with WCF.<br />

However, you can also use binary encoding.<br />

File system access — Silverlight 3 applications are not allowed to read <strong>and</strong> write anywhere<br />

from the client system. You can read <strong>and</strong> write from isolated storage. IsolatedStorageFile<br />

<strong>and</strong> IsolatedStorageFileStream are available. Isolated storage is covered in Chapter 29,<br />

“ Manipulating Files <strong>and</strong> the Registry. ” On a running Silverlight control you can click the right<br />

mouse button to get into the Silverlight menu, where several tabs are available with information <strong>and</strong><br />

confi guration options. The Application Storage tab gives information about the applications using<br />

data with isolated storage, <strong>and</strong> you have control to remove it. You can compare this with cookies of<br />

web applications; just the quotas are very different between cookies <strong>and</strong> the isolated storage. With<br />

Silverlight 4 more control on the fi le system is available.<br />

Browser integration — Because Silverlight controls typically run within a web browser, integration<br />

with the browser is important. You can defi ne .<strong>NET</strong> classes that can be called from JavaScript, <strong>and</strong><br />

also call into HTML <strong>and</strong> JavaScript from Silverlight .<strong>NET</strong> code with classes from the namespace<br />

System.Windows.Browser .<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!