Silverlight 2 RTW bugs

by StefanOlson 14. October 2008 07:00

The Silverlight 2 release came out today.  The first thing I had to do was to revisit all the bugs that I reported during the release candidate period.  They were all reported via the Microsoft connect site, but very oddly they were closed by Microsoft with the reason being External.  Normally when I report a bug that is fixed they will be marked as fixed, so I assumed that they had not been fixed.  Unfortunately I was correct.

Update: it has been pointed out to me that by the time that I started filing bugs, which was five or six days after the release candidate was made available, Silverlight was basically in lock down and only major bugs would be fixed.  This explains why none of these issues were fixed obviously there was some concern about fixing issues in that timeframe that could have caused additional problems.  It is disappointing however that there were only five or six days before everything was locked down.  I was unable to do much development with beta 2 because there were simply too many issues, so I really had to wait for the release candidate.

So to help those of you who are developing Silverlight applications and don't want to waste the amount of time that I have trying to figure out whether these are bugs or not, here are the 7 bugs that I reported, and workarounds where possible:

DataContext = this

Setting the DataContext equal to this causes Internet Explorer to crash!

Workaround:  Rather than using this, you need to create a separate class to contain the items the you wish to be accessible from the data context.  I use DataContext = this; all over the place in the virtual tour software and it is a huge effort to remove that and create separate classes because quite often there are interrelated bindings which makes separating the classes very difficult.

Connect issue.

Converter not called after first time

I suspect this issue may be related to some of the other data binding problems. I haven't spent enough time looking in detail at all of them to be able to track down the exact details of the problems.  I have simply come to the conclusion that it is quicker to avoid using data binding if there are problems.

Using a converter to convert from a boolen into visibility the converter is called the first time but when the value changes thereafter the converter is not called even though the dependency property's value changed has been called.

Workaround: in this case, you would need to manually set the visibility rather than using the binding.

Update: this bug is simply the fact that DependencyProperties don't notify the binding unless you implement INotifyPropertyChanged.  See Silverlight Data Binding bugs explained for details.

Connect issue.

ScrollIntoView does nothing on a listbox

In the Virtual Tour Viewer, when the user types into the lookup field I scroll to the closest possible item.  You can see how this works below: 

 

Unfortunately, in WPF it doesn't actually appear at the top as I have shown it. It actually appears at the bottom if it is scrolling up.  If it is scrolling it down then it will appear at the top.  I have logged a feature request in WPF that there be an option for it to automatically go to the top.

However either way is better than Silverlight.  In Silverlight absolutely nothing happens! 

Update: after digging through the source code via reflector, what I discovered was that if you did not have a scrollviewer named "ScrollViewer" then nothing happens.  Once I renamed my scrollviewer everything worked! Hopefully they will make this clear in the documentation for future releases!

Connect issue

Can't reuse a tooltip in the same way as WPF

The following xaml will cause an exception when you attempt to display the tooltip:

<Grid.Resources>
   <ToolTip x:Key="TT">
      <TextBlock Text="Hello!"/>
   </ToolTip>
</Grid.Resources>
<Button ToolTipService.ToolTip="{StaticResource TT}" Content="button"/>

The code works perfectly in WPF but is just one of many problems with tooltips and Silverlight, and even bigger problem being that the data context of the tooltip is not set.  That means that you can't use binding within the tooltip.  The situation is so bad that in this blog: http://blogs.msdn.com/delay/archive/2008/03/12/lb-sv-why-three-wacky-uses-for-silverlight-2-s-listbox-and-scrollviewer.aspx the work around is to manually create the tooltip in code!  There are a couple of workarounds for the data context issue but they don't appear to work for me at this point, I shall do some more testing.

Workaround: manually create the tooltip in code

Connect issue

Data binding never updates child objects when parent changed

In a number of places in the virtual tour we reference a child, e.g: {Binding SelectedItem.Name}.  When SelectedItem changes, the name will be updated in the UI.  You can see an example here, where the title is the same as the tab name:

However in Silverlight when the selected item changes the data binding is not updated. 

e.g:

Binding b = new Binding("SelectedItem.Name");
b.Source = _descTabs;
BindingOperations.SetBinding(_Title, TextBlock.TextProperty, b);

BindingOperations is a class I have written to be compatible with WPF.  It will be released as part of a library of WPF compatibility functionality in the near future.

This is extremely annoying!

Workaround: Manually update the item in question when the referenced object changes.  This is not quite as easy as it sounds because even if you set up a new DependencyProperty, the changed handler quite often never gets called.  I guess it should be filed that as a separate bug but I was hoping that in the final release of Silverlight at least some of the data binding issues would be resolved and that would make it easier to then isolate any further problems.

Update: this bug is simply the fact that DependencyProperties don't notify the binding unless you implement INotifyPropertyChanged.  See Silverlight Data Binding bugs explained for details.

Connect Issue

Binding to a list and then changing the list fails

This XAML:

<Polygon Points={Binding MyPoints}/>

Then later call:

_dc.Points = new PointCollection();

Doesn't work in Silverlight.  When I put the new point collection into place, Silverlight does not update the polygon.

Workaround: Don't replace the whole collection, just call Clear() on the collection

Update: this bug is simply the fact that DependencyProperties don't notify the binding unless you implement INotifyPropertyChanged.  See Silverlight Data Binding bugs explained for details.

Connect issue

Assigning a point collection to two polygons causes exception

If you assign the same point collection to more than one polygon you will cause an exception (Value does not fall within the expected range).

Workaround: create two separate collections

Connect Issue


So that's it for all the bugs that I reported in Silverlight prior to release.  In the end I gave up on reporting bugs because they kept getting closed on connect.  Development in Silverlight is much more difficult with these bugs.  The biggest concern is data binding which just seems completely and utterly broken in all but the simplest cases.  I had hoped to replace most of my relative source and element name bindings from WPF with the manual bindings created in code.  Unfortunately maybe 75 percent of the time these manual bindings don't work at all!

I hope Microsoft can do better with their next release.  My understanding as this will be released in the near future, most likely called 2.5.  I would therefore expect that it will be demonstrated at PDC in a couple of weeks time.  I hope they focus on improving compatibility with WPF, which at this point is extremely disappointing.

Tags:

Silverlight

Comments

12/31/2008 8:26:17 AM #

I couldn't agree more. The binding implementation in Silverlight is absolutely horrible. It's a shame, because could have been the real power!
You can't even bind to anything but FrameworkElements, so no chance of binding for instance a rotation angle or scale which are "only" DependencyObjects.

Morten

2/25/2009 3:29:23 AM #

Hello!
We develop an application that contains a part which is exactly the same in wpf as in silverlight. I stepped over the same problems as described in this blog!
For instance, today my IE crashes and i don't know why.. so i debugged, and found out that the line "this.DataContext = this;" is the reason for.
Its really "sad" that microsoft havent fixed this issue. that can't be so complicated to fix?!

Thank you for sharing your workarounds!
I hope silverlight get more stable!

Regards

Stefan

7/6/2009 7:11:08 AM #

Silverlight does not support ADO.NET so no surprise about weak data binding.  As for  "=this" why would you want to do that?

Ray Lopez

Add comment




biuquote
  • Comment
  • Preview
Loading



About the author

Stefan Olson is the Managing Director of Olson Software.  He has been developing software using Microsoft Technologies for nearly 20 years.

He is currently working on building the next generation Virtual Tour software in WPF and Silverlight for www.palacevirtualtours.com.