What is new .NET RIA CTP2009 July?
Here is a list of what is new in the July 2009 Preview:
1. A new and improved model for handling operations on the client – you can more easily specify callback/event for an operation, track its status and cancel it.
2. Improved class library support
3. Extensibility points in generated code
4. Cleaner user model and better extensibility support for Application services
5. Better DomainDatasource capability for handling paging and updates.
6. Cleaner shared code support
7. First wave of ADO.NET Data Services alignment (add a DomainService to DataService for writing app logic / expose DomainService as DataService).
8. Bug fixes and initial performance improvement on the server
What Silverlight Class Libraries developer should know ?
In order to write practical code, you need to know quite a bit about the classes you have to
work with. That means acquiring a thorough knowledge of the core class libraries that ship
with Silverlight.
Silverlight includes a subset of the classes from the full .NET Framework. Although it
would be impossible to cram the entire .NET Framework into Silverlight—after all, it’s a 4MB
download that needs to support a variety of browsers and operating systems—Silverlight
includes a remarkable amount of functionality.
The Silverlight version of the .NET Framework is simplified in two ways. First, it doesn’t
provide the sheer number of types you’ll find in the full .NET Framework. Second, the classes
that it does include often don’t provide the full complement of constructors, methods, properties,
and events. Instead, Silverlight keeps only the most practical members of the most
important classes, which leaves it with enough functionality to create surprisingly compelling
code.
• mscorlib.dll. This assembly is the Silverlight equivalent of the mscorlib.dll assembly
that includes the most fundamental parts of the .NET Framework. The Silverlight version
includes core data types, exceptions, and interfaces in the System namespace;
ordinary and generic collections; file management classes; and support for globalization,
reflection, resources, debugging, and multithreading.
• System.dll. This assembly contains additional generic collections, classes for dealing
with URIs, and classes for dealing with regular expressions.
• System.Core.dll. This assembly contains support for LINQ. The name of the assembly
matches the full .NET Framework, which implements new .NET 3.5 features in an
assembly named System.Core.dll.
• System.Net.dll. This assembly contains classes that support networking, allowing you
to download web pages and create socket-based connections.
• System.Windows.dll. This assembly includes many of the classes for building Silverlight
user interfaces, including basic elements, shapes and brushes, classes that
support animation and data binding, and a version of the OpenFileDialog that works
with isolated storage.
• System.Windows.Browser.dll. This assembly contains classes for interacting with
HTML elements.
• System.Xml.dll. This assembly includes the bare minimum classes you need for XML
processing: XmlReader and XmlWriter.
Thats all you need to know to write a Silver Light apps.
Happy Coding.
What Silverlight Class Libraries developer should know ?
In order to write practical code, you need to know quite a bit about the classes you have to
work with. That means acquiring a thorough knowledge of the core class libraries that ship
with Silverlight.
Silverlight includes a subset of the classes from the full .NET Framework. Although it
would be impossible to cram the entire .NET Framework into Silverlight—after all, it’s a 4MB
download that needs to support a variety of browsers and operating systems—Silverlight
includes a remarkable amount of functionality.
The Silverlight version of the .NET Framework is simplified in two ways. First, it doesn’t
provide the sheer number of types you’ll find in the full .NET Framework. Second, the classes
that it does include often don’t provide the full complement of constructors, methods, properties,
and events. Instead, Silverlight keeps only the most practical members of the most
important classes, which leaves it with enough functionality to create surprisingly compelling
code.
• mscorlib.dll. This assembly is the Silverlight equivalent of the mscorlib.dll assembly
that includes the most fundamental parts of the .NET Framework. The Silverlight version
includes core data types, exceptions, and interfaces in the System namespace;
ordinary and generic collections; file management classes; and support for globalization,
reflection, resources, debugging, and multithreading.
• System.dll. This assembly contains additional generic collections, classes for dealing
with URIs, and classes for dealing with regular expressions.
• System.Core.dll. This assembly contains support for LINQ. The name of the assembly
matches the full .NET Framework, which implements new .NET 3.5 features in an
assembly named System.Core.dll.
• System.Net.dll. This assembly contains classes that support networking, allowing you
to download web pages and create socket-based connections.
• System.Windows.dll. This assembly includes many of the classes for building Silverlight
user interfaces, including basic elements, shapes and brushes, classes that
support animation and data binding, and a version of the OpenFileDialog that works
with isolated storage.
• System.Windows.Browser.dll. This assembly contains classes for interacting with
HTML elements.
• System.Xml.dll. This assembly includes the bare minimum classes you need for XML
processing: XmlReader and XmlWriter.
Thats all you need to know to write a Silver Light apps.
Happy Coding.
How to create Stand-Alone Silverlight Project
The easiest way to start using Silverlight is to create an ordinary website with HTML pages and
no server-side code. Here’s how:
1. Select File ➤ New ➤ Project in Visual Studio, choose the Visual C# group of project
types, and select the Silverlight Application template. As usual, you need to pick a project
name and a location on your hard drive before clicking OK to create the project.
2. At this point, Visual Studio will prompt you to choose whether you want to create a
full-fledged ASP.NET website that can run server-side code or an ordinary website with
HTML pages .For now, choose the second option (“Automatically generates
a test page”) to create an ordinary website and click OK.
Every Silverlight project starts with a small set of essential files, as shown in above Figure . All
the files that end with the extension .xaml use a flexible markup standard called XAML
. All the files that end with the extension .cs hold the C# source
code that powers your application.
Here’s a rundown of the files created in project:
• App.xaml and App.xaml.cs. These files allow you to configure your Silverlight application.
They allow you to define resources that will be made available to all the pages in
your application ,and they allow you react to application events such as
startup, shutdown, and error conditions .In a newly generated project,
the startup code in the App.xaml.cs file specifies that your application should begin by
showing Page.xaml.
• Page.xaml. This file defines the user interface (the collection of controls, images, and
text) that will be shown for your first page. Technically, Silverlight pages are user
controls—custom classes that derive from UserControl. A Silverlight application can
contain as many pages as you need—to add more, simply choose Project ➤ Add New
Item, pick the Silverlight User Control template, choose a file name, and click Add.
• Page.xaml.cs. This file includes the code that underpins your first page, including the
event handlers that react to user actions.
Along with these four essential files, there are a few more ingredients that you’ll only find
if you dig around. Under the Properties node in the Solution Explorer, you’ll find a file named
AppManifest.xml, which lists the assemblies that your application uses. You’ll also find a file
named AssemblyInfo.cs, which contains information about your project (such as its name,
version, and publisher) that’s embedded into your Silverlight assembly when it’s compiled.
Neither of these files should be edited by hand—instead, they’re modified by Visual Studio
when you add references or set projects properties.
Lastly, the gateway to your Silverlight application is an automatically generated but
hidden HTML file named TestPage.html . To see this file, make sure you’ve
compiled your application at least once. Then, click the Show All Files button at the top of the
Solution Explorer, and expand the Bin\Debug folder (which is where your application is compiled)
Creating a Simple Silverlight Page
As you’ve already learned, every Silverlight page includes a markup portion that defines the
visual appearance (the XAML file) and a source code file that contains event handlers. To customize
your first Silverlight application, you simply need to open the Page.xaml file and begin
adding markup.
Visual Studio gives you two ways to look at every XAML file—as a visual preview (known
as the design surface) or the underlying markup (known as the source view). By default, Visual
Studio shows both parts, stacked one on the other. Figure shows this view and points out
the buttons you can use to change your vantage point.
As you’ve no doubt guessed, you can start designing your XAML page by dragging controls
from the Toolbox and dropping them onto the design surface. However, this convenience
won’t save you from learning the full intricacies of XAML. In order to organize your elements
into the right layout containers, change their properties, wire up event handlers, and use Silverlight
features like animation, styles, templates, and data binding, you’ll need to edit the
XAML markup by hand.
To get started, you can try creating the page shown here, which defines a block of text and
a button. The portions in bold have been added to the basic page template that Visual Studio
generated when you created the project.
<UserControl x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="100">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<TextBlock x:Name="lblMessage" Text="Hello world."
Margin="5"></TextBlock>
<Button x:Name="cmdClickMe" Content="Click Me!" Margin="5"></Button>
</StackPanel>
</Grid>
</UserControl>
This creates a page that has a stacked arrangement of two elements. On the top is a block
of text with a simple message. Underneath it is a button.
Adding Event Handling Code
You attach event handlers to the elements in your page using attributes, which is the same
approach that developers take in WPF, ASP.NET, and JavaScript. For example, the Button element
exposes an event named Click that fires when the button is triggered with the mouse or
keyboard. To react to this event, you add the Click attribute to the Button element, and set it to
the name of a method in your code:
<Button x:Name="cmdClickMe" Click="cmdClickMe_Click" Content="Click Me!"
Margin="5"></Button>
This example assumes that you’ve created an event handling method named cmd-
ClickMe_Click. Here’s what it looks like in the Page.xaml.cs file:
private void cmdClickMe_Click(object sender, RoutedEventArgs e)
{
lblMessage.Text = "Goodbye, cruel world.";
}
You can’t coax Visual Studio into creating an event handler by double-clicking an element
or using the Properties window (as you can in other types of projects). However, once you’ve
added the event handler, you can use IntelliSense to quickly assign it to the right event. Begin
by typing in the attribute name, followed by the equal sign. At this point, Visual Studio will pop
up a menu that lists all the methods that have the right syntax to handle this event, and currently
exist in your code behind class. Simply choose the right event
handling method.
You can also connect an event with code. The place to do it is the constructor for your
page, after the call to InitializeComponent(), which initializes all your controls. Here’s the code
equivalent of the XAML markup shown previously:
public Page()
{
InitializeComponent();
cmdClickMe.Click += cmdClickMe_Click;
}
event handler at some point during the lifetime of your window. By comparison, the events
you hook up in XAML are always attached when the window object is first instantiated. The
code approach also allows you to keep your XAML simpler and more streamlined, which is
perfect if you plan to share it with non-programmers, such as a design artist. The drawback is
a significant amount of boilerplate code that will clutter up your code files.
If you want to detach an event handler, code is your only option. You can use the -= operator,
as shown here:
cmdClickMe.Click -= cmdClickMe_Click;
It is technically possible to connect the same event handler to the same event more than
once. This is almost always the result of a coding mistake. (In this case, the event handler will
be triggered multiple times.) If you attempt to remove an event handler that’s been connected
twice, the event will still trigger the event handler, but just once.
Testing a Silverlight Application
You now have enough to test your Silverlight project. When you run a Silverlight application,
Visual Studio launches your default web browser and navigates to the hidden browser test
page, named TestPage.html. The test page creates a new Silverlight control and initializes it
using the markup in Page.xaml.
Above Figure shows the previous example at work. When you click the button, the event handling
code runs and the text changes. This process happens entirely on the client—there is no
need to contact the server or post back the page, as there is in a server-side programming
framework like ASP.NET. All the Silverlight code is executed on the client side by the scaleddown
version of .NET that’s embedded in the Silverlight plug-in.
What is relation between Silverlight and WPF
Silverlight and WPF
One of the most interesting aspects of Silverlight is the fact that it borrows the model WPF uses
for rich, client-side user interfaces.
WPF is a next-generation technology for creating Windows applications. It was introduced
in .NET 3.0 as the successor to Windows Forms. WPF is notable because it not only
simplifies development with a powerful set of high-level features, it also increases performance
by rendering everything through the DirectX pipeline. To learn about WPF, you can refer
to Pro WPF in C# 2008 (Apress, 2008).
Silverlight obviously can’t duplicate the features of WPF, because many of them rely deeply
on the capabilities of the operating system, including Windows-specific display drivers and
DirectX technology. However, rather than invent an entirely new set of controls and classes for
client-side development, Silverlight uses a subset of the WPF model. If you’ve had any experience
with WPF, you’ll be surprised to see how closely Silverlight resembles its big brother. Here
are a few common details:
• To define a Silverlight user interface (the collection of elements that makes up a Silverlight
content region), you use XAML markup, just as you do with WPF. You can even
map data to your display using the same data-binding syntax.
• Silverlight borrows many of the same basic controls from WPF, along with the same
styling system (for standardizing and reusing formatting), and a similar templating
mechanism (for changing the appearance of standard controls).
• To draw 2-D graphics in Silverlight, you use shapes, paths, transforms, geometries, and
brushes, all of which closely match their WPF equivalents.
• Silverlight provides a declarative animation model that’s based on storyboards, and
works in the same way as WPF’s animation system.
• To show video or play audio files, you use the MediaElement class, as you do in WPF.
Microsoft has made no secret about its intention to continue to expand the capabilities of
Silverlight by drawing from the full WPF model. In future Silverlight releases, you’re likely to
find that Silverlight borrows more and more features from WPF. This trend is already on display
with the shift from Silverlight 1 to Silverlight 2.
Comparision between Silverlight vs. Flash
The most successful browser plug-in is Adobe Flash, which is installed on over 90 percent of
the world’s web browsers. Flash has a long history that spans more than ten years, beginning
as a straightforward tool for adding animated graphics and gradually evolving into a platform
for developing interactive content.
It’s perfectly reasonable for .NET developers to create websites that use Flash content.
However, doing so requires a separate design tool, and a completely different programming
language (ActionScript) and programming environment (Flex). Furthermore, there’s no
straightforward way to integrate Flash content with server-side .NET code. For example, creating
Flash applications that call .NET components is awkward at best. Using server-side .NET
code to render Flash content (for example, a custom ASP.NET control that spits out a Flash
content region) is far more difficult.
Silverlight aims to give .NET developers a better option for creating rich web content.
Silverlight provides a browser plug-in with many similar features to Flash, but one that’s
designed from the ground up for .NET. Silverlight natively supports the C# language and
embraces a range of .NET concepts. As a result, developers can write client-side code for Silverlight
in the same language they use for server-side code (such as C# and VB), and use many
of the same abstractions (including streams, controls, collections, generics, and LINQ).
The Silverlight plug-in has an impressive list of features, some of which are shared in
common with Flash, and a few of which are entirely new and even revolutionary. Here are
some highlights:
• 2-D drawing.
Silverlight provides a rich model for 2-D drawing. Best of all, the content
you draw is defined as shapes and paths, so you can manipulate this content on the
client side. You can even respond to events (like a mouse click on a portion of a
graphic), which makes it easy to add interactivity to anything you draw.
• Controls.
Developers don’t want to reinvent the wheel, so Silverlight is stocked with a
few essentials, including buttons, text boxes, lists, and a grid. Best of all, these basic
building blocks can be restyled with custom visuals if you want all of the functionality
but none of the stock look.
• Animation.
Silverlight has a time-based animation model that lets you define what
should happen and how long it should take. The Silverlight plug-in handles the sticky
details, like interpolating intermediary values and calculating the frame rate.
• Media.
Silverlight provides playback of Windows Media Audio (WMA), Windows Media
Video (WMV7–9), MP3 audio, and VC-1 (which supports high definition). You aren’t
tied to the Windows Media Player ActiveX control or browser plug-in—instead, you
can create any front-end you want, and you can even show video in full-screen mode.
Microsoft also provides a free companion hosting service (at http://silverlight.live.
com) that gives you space to store media files. Currently, it offers a generous 10 GB.
• The common language runtime.
Most impressively, Silverlight includes a scaled-down
version of the CLR, complete with an essential set of core classes, a garbage collector, a
JIT (just-in-time) compiler, support for generics, threading, and so on. In many cases,
developers can take code written for the full .NET CLR and use it in a Silverlight application
with only moderate changes.
• Networking.
Silverlight applications can call old-style ASP.NET web services (.asmx) or
WCF (Windows Communication Foundation) web services. They can also send manually
created XML requests over HTTP and even open direct socket connections for fast
two-way communication. This gives developers a great way to combine rich client-side
code with secure server-side routines.
• Data binding.
Although it’s not as capable as its big brother, WPF, Silverlight data binding
provides a convenient way to display large amounts of data with minimal code. You
can pull your data from XML or in-memory objects, giving you the ability to call a web
service, receive a collection of objects, and display their data in a web page—often with
just a couple of lines of code.
Of course, it’s just as important to note what Silverlight doesn’t include. Silverlight is a new
technology that’s evolving rapidly, and it’s full of stumbling blocks for developers who are used
to relying on .NET’s rich libraries of prebuilt functionality. Prominent gaps include a lack of
database support (there’s no ADO.NET), no support for 3-D drawing, no printing, no command
model, and few rich controls like trees and menus (although many developers and
component companies are building their own). All of these features are available in Windowscentric
WPF applications, and they may someday migrate to the Silverlight universe—or not.