Rants Tagged with “Silverlight 2”

<<  <  3  4  5  6  7  8  9  10  11  12  13  >  >>  (Total Pages: 13/Total Results: 121)

Geek Dinner in DC

Silverlight Logo

G. Andrew Duthie has done me a big favor by organizing a Geek Dinner while I am in the DC area next week.  If you're in DC and want to gab about Silverlight, ADO.NET, Astoria, how cool your phone is or why the destruction of the Roman empire was the start of the modern era...come on by.  Please visit Andrew's Blog to RSVP.

Great Tutorial on the Visual State Manager

Silverlight Logo

While I try not to do too much link spam in my blog, this link is worth it. 

Ian Griffiths (of "Programming WPF" fame) has a great tutorial and explanation of the Visual State Manager.  If you are trying to get your head around this and how it differs from the Beta 1 Storyboard TemplateParts, this is a great introduction. Unlike Scott Guthrie's great introduction, Ian (as usual) digs deep into the XAML and code to explain what and why, not just how.  I thoroughly recommend it.

I can't vouch for his plug at the end as I am biased towards my own workshop ;)

Only a few seats left...for Beta 2

Silverlight Logo

There is only a week left before my Washington, DC stop on the Silverlight Tour.  This event is special because its the first workshop based on the Silverlight 2 Beta 2 bits.  If you are on the cutting edge and want to get the latest experience with Silverlight 2, don't forget to register! There are only a few seats left for this tour stop.  See the site for details!

Debugging ADO.NET Data Services...with Fiddler2

Silverlight Logo

When I deployed the small test application (http://www.silverlightdata.com/simple), it was pretty apparent that it was performing really badly. Some of this is because my ISP upload speed isn't great but it was still taking far too long I thought.  This was a simple app with not much data, so I knew I wanted to find out what was happening. If you haven't seen the site, its basically an editor for the Product table in the Northwind database.  Nothing special really.

ADO.NET Data Services does a lot of work for you under the covers.  This is good because we're not being asked to write a lot of serialization and transportation code, but it can be bad because it becomes more difficult to see why things are happening. Fiddler2 to the rescue!

If you're not familiar with Fiddler2, its basically a great tool for watching web traffic so you can see what is actually happening over the wire. For ADO.NET Data Services, we want to see the actual communication over the wire to see what was being sent to and from the Silverlight application.  First, grab the Fiddler2 tool (http://fiddler2.com/) and come with me!

So I fire up Fiddler2 and run the example page.  What do I see?  Nothing.  None of the traffic is showing up. A quick Google search reveals that Fiddler doesn't work on localhost or 127.0.0.1 (kinda the same thing). I found an odd workaround...add a period after the IP address.  So my "http://localhost:8000/Default.aspx" test page became "http://127.0.0.1.:8000/Default.aspx".  The period after the "1" is not a mistake.  Once I did that, the requests were showing up in Fiddler2.  Wahoo!

So what did I see? Here's a look at the Fiddler2 window (You can click it for a bigger view):

Looking at the request to Products.svc, I picked the "TextView" tab to see the actual body of the message.  Looking at it I noticed this Picture property that was base-64 encoded.  Uh oh...I didn't even notice that we are getting pictures...in fact we're getting duplicate data. My LINQ request was:

var qry = from p in TheContext.Products.Expand("Supplier")
                                       .Expand("Category")
          orderby p.ProductName
          select p;

I knew that I would be getting duplicate data by using the Expand extension method.  Expand says to embed the related entity (the Supplier and the Category) so that our object model doesn't have to lazy load them. Of course I wasn't paying attention.  The Category has a picture stored in the database. I am not even using it (and couldn't since the image is a GIF and Silverlight can't display GIFs) so retrieving it is pretty useless. Here's a quick view of the underlying Entity model:

The fix for me was to simply remove it from the model, but I am looking at different ways of really solving it including delving into how the "select" statement might filter these out, though I expect that doing three queries (one for Products then just returning Suppliers and Categories to remove the duplicate data would be much more efficient yet.

One caveat, this is the first release of the ADO.NET Data Services' Silverlight Client Library so give it time to improve some of the performance issues.  But like other data access libraries, sometimes small changes can make large improvements in performance.

Hope this helps you debug your own ADO.NET Data Services projects.

Silverlight 2 Beta 2 Sites

Silverlight Logo

I've updated several of our sites that contain Silverlight 2 Beta 2 projects/apps.  Here they are:

Upgrading your Silverlight 2 Projects to Beta 2?

Silverlight Logo

UPDATED: Essentially, no one else did write a bunch of upgrading blogs so I've amended this blog post to include more infomation on how to upgrade your projects.

When opening your projects in Visual Studio after Silverlight 2 Beta 2, you will be prompted to upgrade your project as shown below:

Upgrade Dialog

This upgrade with change the project references for you and in most cases remove the System.Windows.Controls.Extended.dll reference. Once the project is converted, you will see a number of changes to make:

  • Tooltips have changed and some functionality has been removed.  For the most part changing from ToolTip="..." to ToolTipService.ToolTip="..." will fix most simple usage of the control.
  • If you're not using the Calendar, GridSplitter or DatePicker, remove the System.Windows.Controls.Extended.dll from your references.  You don't need it for most controls anymore and its pretty big so it will just balloon the size of your .xap files.
  • If you are using ControlTemplates, you may need make a lot of changes. Look again at the default templates (Reflector is a good way of getting the generic.xaml that contains all the templates) to see how you should change them.  TemplateParts have changed names and they are mostly using VisualStateManager for transition effects. Alternatively, the Blend support for VisualStateManager is really good and removing your ControlTemplates and recreating them with Blend is often the better solution.
  • If you are using the DataGrid control, you will need to do a substantial amount of re-work as the DataGrid has changed a heck of a lot. The biggest change for most people is that AutoGenerateColumns is now true by default.
  • Upgrade to the new Silverlight.js to your project if you are using it to host your project.  Its is in the SDK directory under "Tools".
  • If you are using the OBJECT tag to include Silverlight, you will need to change the MIME type from "application/x-silverlight-2-b1" to "application/x-silverlight-2-b2".
  • If you use WebClient, you may need to add a reference to System.Net.dll.
  • When you use any networking code (WebClient, et al.), it used to throw exceptions during the execution (on the other thread) which breaks the APM model.  Silverlight 2 now throws this exception when you retrieve the results on the callback.  This means you will need to trap those errors with try...catch blocks around the results reference in the callback.
  • Any DeepZoom images will need to be regenerated with Deep Zoom composer as the format of the file (was .bin, now .dzi or .dzc) has changed to XML.
  • Web service use has changed and now actually reads the .clientconfig file.  So if you are having trouble getting your services working, make sure the values in the .clientconfig  file are accurate.
  • Dynamic XAML (using XamlReader.Load) has changed so that a private namescope is created by default. This is a significant change that means that referring to named elements inside your Dynamic XAML (or using FindName to locate an item) will fail.
  • x:Key and x:Name for Resources are now mutually exclusive.  If you were doing the trick of using an x:Key so that you could do StaticResource but using x:Name to get a reference in your code-behind file, this no longer works.  To get the item in your codebehind, call Resource["keyname"] instead.
  • IsolatedStorage defaults have been increased from 1KB to 10MB. If you need to increase the API has changed to IsolatedStorageFile.IncreaseQuotaTo.
  • OpenFileDialog.ShowDialog now returns a boolean instead of a DialogResult.
  • WatermarkedTextBox has been removed, you will need to replace these with simple TextBox.

The SDK comes with a deeper document that discusses all the changes that are important.  Read this...I only have covered the big picture items.

Hope this helps those of you doing late night conversions like I am doing!

Using ADO.NET Data Services in Silverlight 2 Beta 2

ADO.NET Data Services

UPDATE: I had the PUT/POST reversed.  It reads correctly now.  (Thanks to commenter Rob for pointing it out).

Now that Silverlight 2 Beta 2 has launched, we have the ability to consume ADO.NET Data Services (formerly Astoria) from within Silverlight projects. ADO.NET Data Services are a perfect match for client-side technologies like Silverlight and ASP.NET AJAX.

For the uninitiated, ADO.NET Data Services is a new part of the .NET 3.5 framework that supports exposing a data model (e.g. LINQ for SQL, Entity Framework, etc.) as a set of queryable REST endpoints. ADO.NET Data Services maps the four data verbs into the four HTTP verbs:

  • Create == POST
  • Read == GET
  • Update == PUT
  • Delete == DELETE

Essentially it provides a way to use a data model across the firewall. It works by exposing IQueryable endpoints through a URI-based syntax allowing developers control over how the data is retrieved through:

  • Filtering
  • Sorting
  • Paging
  • Shaping

In addition ADO.NET Data Services utilizes JSON and Atom (though Plain Old XML may be supported eventually) as the serialization formats. These make it easy to consume in client-side interfaces like Silverlight and AJAX. For more information on ADO.NET Data Services, see there site:

http://msdn.microsoft.com/en-us/data/bb931106.aspx

Before you can consume a Data Service in Silverlight, you will need to create a model and service.  See Guy Burstein's walkthrough of creating the service here:

http://blogs.microsoft.co.il/blogs/bursteg/archive/2008/05/12/visual-studio-2008-sp1-ado-net-data-service-walkthrough.aspx

You *can* use LINQ to SQL as your data model but currently it does not have support for updating via ADO.NET Data Services so if you need to read and write data, you should start with an Entity Framework data model.

In Silverlight 2 Beta 2, ADO.NET Data Services is composed of an in-memory library allows asynchronous LINQ queries that are translated into the URI syntax automatically. Before you can get started you will need a a client-side version of the Data Context object and data contract classes for the entities in your data model. To do this, simply use the DataSvcUtil.exe tool located in the C:\Windows\Microsoft.NET\Framework\v3.5\ directory. Typically you would call it by specifying the URI of the service, the name of the class file to create and what language to use:

DataSvcUtil.exe /uri:http://localhost:8888/YourService.svc 
                /out:dataclass.cs 
                /language:CSharp

Once that class is created, add it to your Silverlight project.  You will also need to add a reference to the System.Data.Client.Services.dll assembly. Now we are ready to get some data. 

First we need to create an instance of the context class.  This class exposes each of the model types as queryable properties.  When creating an instance of the class, you must specify a URI to the service itself:

NorthwindEntities ctx = 
  new NorthwindEntities(new Uri("/Products.svc", UriKind.Relative));

Querying data with Data Services looks much like any other LINQ-based query:

var qry = from p in ctx.Products
          orderby p.ProductName
          select p;

Normally, you could execute the query directly by calling something like ToList() against the query.  Since that operation would cause a synchronous web request to happen across the network, that isn't supported in Silverlight 2 Beta 2.  In fact, if you try you will simply get a NotImplemented exception. In order to execute these queries, you will need to cast the query into a DataServiceQuery.  The DataServiceQuery allows you to call BeginExecute to start an asynchronous query as seen below:

// Cast the query to a DataServiceQuery
DataServiceQuery<Product> productQuery = 
                                  (DataServiceQuery<Product>)qry;

// Start the execution
productQuery.BeginExecute(new AsyncCallback(OnLoadComplete), 
                          productQuery);

Once the query completes, it will call the OnLoadComplete method that was specified in the AsyncCallback.  In this method, you first grab the DataServiceQuery that you sent with the request then end the execution to retrieve the results as seen below:

void OnLoadComplete(IAsyncResult result)
{
  // Get a reference to the Query
  DataServiceQuery<Product> productQuery = 
    (DataServiceQuery<Product>)result.AsyncState;

  // Get ther esults and add them to the collection
  List<Product> products = productQuery.EndExecute(result).ToList();
}

While its not as straightforward as synchronous execution, the new ADO.NET Data Services certainly works well in Silverlight 2 Beta 2 and provides a great way to use existing or planned data models over Internet applications. There are a couple of caveats:

  • Error handling and communication is very confusing right now as most real errors are being swallowed by the server instead of communicating back to the client. To find out what is really happening, use of Fiddler and enabling breaking on the throwing of all .NET exceptions will help a lot.
  • There are bugs on updating data that may get in your way.  Using Batch Saves will solve most of these issues.
  • Currently the Data Contract objects do not support INotifyPropertyChanged or INotifyCollectionChanged so data binding may be affected in some cases.There are partial methods for detecting changes to specific properties which makes implementing the INotifyPropertyChanged interface trivial, but not quick. Future versions (e.g. post-RTM) will give us better control over the generation of the data contract classes.
  • There is no built-in Visual Studio support to build the data contract/context classes.  This is also coming soon, though the exact schedule is unknown.

I am currently working on two examples for this (a simple one and a more complex one) as well as an article for MSDN, all of which will greatly expand the details of how to use ADO.NET Data Services (including how to save changes back to the server. Be sure to watch here for details of those samples and articles.

What's Changed in Silverlight 2 Beta 2?

Silverlight Logo

The Silverlight Team has been burning the candles at both ends. To our benefit they have delivered Beta2 of Silverlight 2. The changes between Beta 1 and Beta 2 are not as dramatic as you may have experienced between Silverlight 1.1 Alpha and Silverlight 2 Beta 1.  But some major changes have been made.

There are specific instructions about what code actually needs to be fixed in your projects.  These instructions are contained in the change documentation that ship with the Beta 2 package.  You can download the new Silverlight 2 Beta 2 from the Silverlight.net site:

Scott Guthrie also has a detailed post of some of the changes and a nice walkthrough of using the VisualStateManager and ControlTemplate authoring with Blend:

Here are the changes that I found while converting my old sites and writing some new sites:

Framework Changes

SDK Controls versus Plugin Controls

The most starling change for me was the fact that they merged most of the controls that used to be in System.Windows.Controls.dll into the System.Windows.dll assembly. The impact this has is to reduce the overall size of a .xap file since you can now depend on most of the controls from the plug-in.  In Silverlight 2 Beta 1 a "Hello World" app's .xap file started at an astounding 230K in size.  In contrast the Beta 2 "Hello World" .xap is only 4K.

Microsoft has the challenge of putting as much functionality as possible in the plug-in without it getting so large that is off-putting to users to download and install.  The inclusion of the controls into the runtime has ballooned it up from 4MB to about 4.5MB, but overall I think this was a critical decision.

Isolated Storage Size

The default size of Isolated Storage is now at 1MB (instead of 1KB in Beta 1).

Event Bubbling Cancellation

In Beta 1 (and prior), event bubbling could not be cancelled.  The framework allowed you to mark the event as handled, but not actually stop the bubbling from occurring.  In Beta 2 this changes and when you mark an event as handled, it is not propogated through the render tree:

void nested_MouseEnter(object sender, MouseEventArgs e)
{
  // Cancels the bubbling
  e.Handled = true;
}

Silverlight.js has Changed

The Silverlight.js script has been changed and updated in the Beta 2 SDK so you will need to replace this script anywhere you are deploying Beta 2 projects to ensure compatibility.

DataBinding Changes

The FrameworkElement class (the base class of most visual elements in Silverlight) now supports a BindingValidationError event that is thrown when data binding fails to correctly bind to TwoWay binding. To support this, the Binding class now supports NotifyOnValidationError and ValidatesOnExceptions properties to turn on validation error notification.

Code-only Storyboards

You can now create Storyboards in code that can animation parts of the render tree without having to be added to the render tree.  This allows you to create Storyboards (and embedded animations) in code alone. 

Cascading Properties

Beta 2 moves a number of important properties to the Control class which has the effect of allowing you to specify these properties on the UserControl and have the child Control's default properties to cascade.  These properties include:

  • Foreground
  • FontFamily
  • FontSize
  • Etc.

If you set these in the UserControl (or other Control-based parent), the children will 'inherit' these properties.  For example:

<UserControl x:Class="SilverlightApplication5.Page"
             xmlns="..."
             xmlns:x="..."
             Foreground="Blue"
             FontSize="24">
  <Grid x:Name="LayoutRoot">
    <TextBox Text="Hello" />
  </Grid>
</UserControl>

XamlReader and Namescopes

Using the XamlReader to build dynamic XAML at runtime has the side effect now of always creating a namescope for the XAML.  Prior to Beta 2, you could optionally create a namescope.

If you're not familiar with namescopes, this blog entry explains it really well:

http://nerddawg.blogspot.com/2007/05/namescopes-in-silverlight.html

Control Changes

Changed TemplateParts

If you have used ControlTemplates in your Silvelright 2 Beta 1 applications, some of the templates (most notably the TextBox) have changes quite a bit. This means that you may need to rename some of the TemplateParts in your applications to make them continue to work.  Review the TemplateParts for any control where you are using a ControlTemplate.  The behavior when you have a mismatch between ControlTemplates is that the rendering will simply fail and your app stop working.  Unfortunately there are no compile-time checks or exceptions thrown when you get this wrong.

Introducing the VisualStateManager

In Beta 2, Microsoft introduces a new concept to handle changes to the UI in reaction to user input.  For example, handling when a user hovers over a control, the control has focus, etc. Prior to Beta 2 you would define TemplateParts for Storyboards but the way this is defined was hard for designers to handle when creating a control.  To The VisualStateManager instead has groups of Visual States that each have their own duration and other properties. Effectively it means that it will be easier for designers (using Blend or in raw XAML) to create these transitions than was possible prior to Beta 2.

There isn't enough room in this blog post to explain it in detail but I should be posting something in depth about this very soon.

New Control: TabControl

Added to Beta 2 is a TabControl class that supports standard tab control functionality. 

Multiline TextBox

The TextBox now supports multi-line data entry via the new AcceptsReturn and TextWrapping properties.  These will allow you to specify the exact behavior you want (instead of simply enabling multi-line support.

WatermarkedTextBox is Gone

The WatermarkedTextBox control has been removed.  There may be ways of accomplishing this without the control, but there are no current plans to re-introduce this control.

Extended Control Changes

The System.Windows.Controls.Extended.dll still exists and contains some key controls that you might need:

  • Calendar
  • DatePicker
  • GridSplitter
  • TabControl

In order to use these controls you will need to import the assembly into your project and import the namespace into your XAML.  No longer will these work with the default namespace. 

Tooltip Changes

ToolTips can no longer be set directly but must use the ToolTipService class to add it to any element. For example:

<Button ToolTipService.ToolTip="This is ToolTip text"/>

DeepZoom Changes

As part of Beta 2, there is a new DeepZoom Composer tool.  Prior to Beta 2, the image information was a collection of images and a binary file (.bin) that contained the metadata about the the images.  In Beta 2, this file is now an xml file to support consistency and versioning (called .dzi).

DataGrid has Changed

The DataGrid has continued to mature to include new features like column reordering, row sorting and more granular control templates.  Any DataGrid's you are currently using may need to be reworked...but you will get a lot more functionality than you had in Beta 1.

Networking Changes

Web Service Changes

Web Services now support cross-domain service requests (using the cross-domain policy files). WCF Services now support duplex services but basicHttpBinding is still the only supported binding.

ADO.NET Data Services Support

The ADO.NET Data Services (aka Astoria) client support for Silverlight is now included in the SDK. Note that you need .NET 3.5 SP1 (beta) and Visual Studio 2008 SP1 (beta) both installed to write the server-side ADO.NET Data Services to make this work, but the client library is now included.  It has a similar model to the .NET Client Library but all requests are asynchronous.  I *will* be covering this soon in articles and in this blog so if you're interested in ADO.NET Data Services from Silverlight 2...its coming.

Web Request Exception Changes

Prior to Beta 2, any exceptions during an asynchronous web request would happen on the background thread making it difficult to handle exceptional conditions. In Beta 2, the exception will be thrown as the accessor to the Result is called. This means you will now need to use try...catch blocks around access to the Result property to catch security exceptions in your web request code.

ServiceReference.clientconfig

Web Service calls that are made using a Service Reference will now use the setting contained in the ServiceReference's .clientconfig file (a new file generated during the proxy generation).  If you want to make changes to the service binding or other parameters, making them in the .clientconfig file is now the way to do that.

Header Support in Cross Domain Policy

In Beta 2, the cross domain requests now specifically prohibit the use of headers unless they are allowed in the cross domain policy file.

Sockets Change

Sockets now support connections to any server that enables the cross domain policy files.  In addition, the range of ports has been widened to allow for more typical socket communication to be available.

Tool Changes

Silverlight Linkage Changes

Links between ASP.NET projects and Silverlight projects now allow you to specify build-specific directories so you can have two versions of a .xap file (e.g. Debug and Release). In addition, the "Add Silverlight Link..." option on the context menu has been removed.  You can create links to Silverlight projects (and make changes) now in a new Silverlight Tab in the Project properties of the ASP.NET projects.

"Add Service Reference..." Changes

The default collection type for Data Contracts is now ObservableCollection<> (which you can still change with the "Advanced" options. If you're not familiar with the collection type, the ObservableCollection<> type can notify a container when the collection changes (e.g. add/remove/insert). This is used by Silverlight's Data Binding to allow OneWay and TwoWay bindings to work against collections.  The switch from Array to ObservableCollection<> is the right decision AFIAC.

Blend Changes

Blend 2 June Preview includes new features to make some common tasks easier to use including:

  • ControlTemplate editing support in Blend
  • VisualStateManager Support (to create state transitions)
  • New Breadcrumb Navigation in designer
  • Enabled the "Make Button" functionality (Select items and make a button control template from those items).
  • Font Embedding Support (if you drop a font in your Silverlight 2 project, it will be available from the list of Fonts).

What is Still Missing?

There is still room for improvement and certainly as we head into Silverlight 2 RTM, I expect to see more additions.  Here is a list of what I think is still missing and from Microsoft's public statements, they are likely to be included:

  • ProgressBar control
  • ComboBox control
  • Better WCF Support

Whew!  I am sure I didn't cover all the changes but these are the big ticket items that I saw in converting my own projects over.  Let me know in comments if you find more.

The Document Outline in Visual Studio 2008

Silverlight Logo

Something I never noticed before is the Document Outline window in Visual Studio (2008?).  When editing large XAML files this is particularly useful to help navigate the tree of elements.

If you've never noticed it like me, you can make it show up by using the menu's when a XAML file is open:  View->Other Windows->Document Outline. Alternatively, the default key command is Ctrl-Alt-T.

This is *not* a Silverlight specific feature.  It works with WPF as well (but not ASP.NET pages). Nice....

 

 

 

 

Silverlight Beta 2 Announced - Silverlight Tour Follows Suit

Silverlight Logo

As announced at TechEd today in Orlando, Silverlight 2 Beta 2 is going to be released later this week. 

Now that its been announced, we can verify that starting with the June 16th class, the Silverlight Tour will now be teaching the workshop based on the Silverlight Beta 2 bits.  If you've been waiting for Beta 2 to attend a class, the Washington, DC stop of the Silverlight Tour (only a couple weeks away) is the right class for you.  Sign up soon as we only have a handful of seats left for that stop.