Silverlight »

[10 Nov 2009 | 1 Comments]

A while ago, we were busy developing custom controls for Silverlight (2 at the time).  One of those controls was a Wizard control, which in turn consisted of a list of another custom control, the WizardSlide.  Obviously, this list was implemented as a Dependency Property “WizardSlides” (collection of WizardSlide) on the Wizard control. 

 

However, after some testing, I noticed some pretty strange behaviour: everything worked quite fine when only one instance of the Wizard control was used in our application, but from the moment on we started using multiple instances, the WizardSlides-collection property seemed to behave itself as if it were defined on the class instead of on the instance of the class.  All of a sudden, we were able to access the combined WizardSlides of instances 1 & 2 through the WizardSlides property on either of the Wizard instances.  To make matters even more strange, this didn’t happen if the collection property contained a simple type (like string or int), but it did happen when it contained a UIElement (or derived) type (like the WizardSlide control). 

 

We tried lots of different approaches to solve this problem, searched the internet, posted questions on the Silverlight forum, but to no avail: no-one could explain why this happened nor offer a solution, and we finally opted for a less-than-ideal approach, constricting the number of WizardSlides to 8 instead of having a dynamic collection.

 

Last week, I was helping out one of our clients with their Silverlight application.  An application which uses custom controls.  One of which contained a collection that seemed to behave as a singleton instead of on an instance level…  I remembered the problems I faced with this before, already thinking we wouldn’t find a solution to keep this collection dynamic.  However, I started searching around again, and lo and behold, it wasn’t long before I found this page on MSDN, describing the exact problem we were facing AND offering a reason and solution.  I am, by the way, 100% sure this page wasn’t there last year ;-)

 

Apparently, what’s happening is this: when you create a dependency property, it gets its default value through the dependency property metadata you define.  If that property is a reference type, this default value isn’t a default value per instance, it is a default value that applies to all instances of the type.  This means that when using the collection defined by the collection property metadata (which is singular/static!) as the default value for new instances, your collection dependency property is actually referring to that singular collection, and is thus accessible through any instance of your control!

 

Interesting, no? :)  What’s even more interesting is that there is a very, very easy to solve this: to make sure your collection property isn’t shared between all instances of your control, reset the property value to a unique instance as part of the class constructor call.  In the Wizard control with a WizardSlides collection, this looks as such:

 

public Wizard() : base()
{
//... other constructor tasks

SetValue(WizardSlides, new ObservableCollection<WizardSlide>());
}

 


Hope this helps some of you out! :)

Presentations and sessions »

[9 Nov 2009 | 0 Comments]

In the next few weeks, I’ll be speaking at a few events.

 

  • Tuesday November 17th: RIA Evening Seminar @ KHM

I’ll be speaking about Rich (Internet) Applications, mainly focussing on Silverlight. In this 90 minute session. I’ll talk about the “why” and “what” of rich applications, and show off a few of the features that make Silverlight stand out.

Location: Katholieke Hogeschool Mechelen (website)

  • Wednesday November 25th: Microsoft User Experince @ Vitra

    For the second time, Microsoft is organizing this event together with Vitra & partners.  This event is aimed at developers & decision makers, and consists of in depth sessions on Sharepoint, Silverlight, WPF and Sketchflow in the afternoon (@ MS Corporate Village, Zaventem), and short introduction sessions in the evening (@ Vitra showroom, Diegem).  I’ll be presenting the Silverlight session: this is a 45 minute session, repeated throughout the afternoon.  In this session, I’ll talk about Silverlight 3 & its new features.

 

Don’t hesitate to say hello if you see me! :)

BESUG, Presentations and sessions »

[19 Oct 2009 | 0 Comments]

Last Thursday, I presented a BESUG session on RIA Services. 

Code & slides are online now, feel free to download them and have a look.  Most of RIA Services is covered, including but not limited to CRUD, Validation, extending generated code, Authentication and Authorization.  The Silverlight solution itself is built using a (pragmatic ;-)) MVVM approach.

Silverlight »

[7 Oct 2009 | 0 Comments]

Just now, I was surfing on the Infragistics site, having a look at their control suites.  I noticed their latest press release, concerning the development of a custom UI on Silverlight for MS Windows Embedded CE 6.0 R3

 

I was amazed.  Silverlight, on Windows Embedded CE?  That’s new. 

 

So I assumed this was just an announcement for something that would be released somewhere in the future.  Nevertheless, I decided to surf around some more, looking for more information, and sure enough I stumbled upon this page on the Microsoft site, which explicitly states Silverlight for Windows Embedded has been released, “enabling designers and developers to create exciting and visually compelling user interfaces for embedded devices”.  This update to Windows Embedded CE has been available since last week, and it can be downloaded here (update).

 

So, how come this wasn’t announced with lots of bells and whistles??  Beats me (well, maybe I just missed it ;-)), but nevertheless: way to go, Silverlight! ;-)  We can now design Silverlight applications for thin clients, set-top boxes, VoIP Phones, GPS devices, handheld terminals, …!

 

Update!  This is NOT the same Silverlight version you’d use for developing regular Silverlight applications, more information can be found here – yet it’s certainly a step in the right direction.

Silverlight, .NET, MVVM »

[6 Oct 2009 | 0 Comments]

When you’re working with the Model-View-ViewModel pattern in Silverlight, sooner or later you’ll run into the same problem most of us run into: what about animations?  Theoretically, if you want to follow the MVVM design pattern you’re using, your animation should be initiated from the ViewModel (no code behind on your View, remember?), but due the separation between your View and your ViewModel, the ViewModel shouldn’t know about a specific View.  It should exist indepently of it, so, for example, you can easily use the same ViewModel for multiple Views.

 

So, how do you solve this problem?  How do you get animations on your View while still respecting the MVVM pattern (more or less so, depending on your implementation)? 

 

Binary Bob has a very, very interesting post about this on his blog.  He talks about the problem, and then discusses several options on how to solve it, including sample code.  I especially like the StoryBoardManager-solution.  Make sure you check it out!

 

Silverlight »

[30 Sep 2009 | 1 Comments]

As I mentioned earlier, I submitted my Silverlight Drag Drop Manager to the Silverlight Control Builder contest.  I promised I’d let you know how it went, and… apparently, I won first prize! :-)

 

Should look nice on the codeplex page I suppose, and it’s always nice to get some appreciation.  So, thank you, Page Brooks and judges, I’m really, really happy with this! :)

Silverlight, WCF RIA Services »

[27 Sep 2009 | 0 Comments]

As some of you might know, the company I work for is hosting a BESUG session on Silverlight & RIA Services shortly (October 15th / click here to register!), for which I am the speaker.  At the moment, I’m composing a few of the slides and writing up some code, and I was wondering: if you had the possibility to ask a question about RIA Services, what would it be?

 

I’m not talking about the more general things (like “how do I get to my data”), those things will be addressed.  I’m looking for more specific questions, like “how do you work around having to rewrite code when you regenerate your DomainService?“, or “what are good strategies to achieve X or Y?” Hoping for some input on this, I decided to quickly blog this. ;-)

 

 

So, in short: what would YOU like to know about RIA Services?  Let me know (mail, twitter, or by replying to this post).  Tnx!