[5 Mar 2014 | 0 Comments]
Recently, I was busy building a custom WinRT behavior, and I ran into what I thought was an unusual problem: I created a dependency property (IList), but somehow the PropertyChangedCallback would never fire. Sounds familiar? 
[More]

General, Featured, .NET, RealDolmen, Presentations and sessions »

[28 Mar 2014 | 0 Comments]

Yesterday evening I delivered a session for the RealDolmen Microsoft Community user group on Fluent API building (in short: how to build a component that allows method chaining with improved code readability, with a bit of lambda’s & expression trees thrown into the mix).  There’s an overview of what I talked about here.

 

I’d like to thank everyone for the great turn-out, and as promised, you can download the code for that session from my OneDrive.  I added a bit of extra expression tree manipulation in there, for those who are interested in that stuff :-)

 

Hope you enjoyed it as much as I did, and happy coding! :-)

.NET, Featured, Headline, Windows 8, WinRT »

[5 Mar 2014 | 0 Comments]

Recently, I was busy building a custom WinRT behavior, and I ran into what I thought was an unusual problem: I created a dependency property (IList<T>), but somehow the PropertyChangedCallback would never fire.  Sounds familiar?

 

This is the code:

 

public static DependencyProperty ValidationErrorsProperty =
 DependencyProperty.Register("ValidationErrors",
 typeof(IList<ValidationError>), typeof(ValidationErrorBehavior),
 new PropertyMetadata(null, OnValidationErrorsChanged
   ));

public IList<ValidationError> ValidationErrors
{
    get { return (IList<ValidationError>)base.GetValue(ValidationErrorsProperty); }
    set { base.SetValue(ValidationErrorsProperty, value); }
}

 

 

I was a bit flabbergasted (always wanted to use that word ;-)), really.  I’d written stuff like this in WPF & Silverlight before, without any problems.  So I enabled native code debugging to check out what was going wrong.  The problem was related to a converter error: “failed to convert List<ValidationError> to IList<ValidationError>”.  So it wasn’t just the PropertyChangedCallback that wasn’t firing – it’s a conversion problem (by the way, this is why native debugging is a *really* great option when you run into problems like this).

 

At first glance, that might look like a bit of a weird problem: why wouldn’t the built-in converter be able to convert a List<T> to IList<T>, while List<T> implements IList<T>?  Well, it’s a problem of implicit conversion, which is what’s used by the built-in converter: List<T> implements IList<T>, so it can implicitly convert that way, but logically, not the other way around.

 

So, how do you solve something like this?  There’s two different solutions, depending on the scenario you’re trying to achieve.  The first one is removing the need to convert by working with List<T> instead of IList<T>.  We’re now working with an implementation instead of with an interface – so there’s no need to implicitly convert anymore.  I’m not a big fan of this, though – this would require anyone working with the behavior to provide a List<T>, instead of any collection type that implements IList<T>.  In other words: it imposes constraints on the consumer that shouldn’t be there.  That scenario results in this code:

 

public static DependencyProperty ValidationErrorsProperty =
   DependencyProperty.Register("ValidationErrors",
   typeof(List<ValidationError>), typeof(ValidationErrorBehavior),
   new PropertyMetadata(null, OnValidationErrorsChanged
     ));

public List<ValidationError> ValidationErrors
{
    get { return (List<ValidationError>)base.GetValue(ValidationErrorsProperty); }
    set { base.SetValue(ValidationErrorsProperty, value); }
}

 

 

Another solution is registering the DependencyProperty as typeof(object) instead of typeof(IList<T>), BUT at the same time constraining what can be provided by ensuring the bindable property is of type IList<T>, so the consumer can’t just provide any object.  And this fits my requirements: failed implicit conversion is avoided, and the consumer can provide anything that implements IList<T>.  This results in this code:

 

public static DependencyProperty ValidationErrorsProperty =
   DependencyProperty.Register("ValidationErrors",
   typeof(object), typeof(ValidationErrorBehavior),
   new PropertyMetadata(null, OnValidationErrorsChanged
     ));

public IList<ValidationError> ValidationErrors
{
    get { return (IList<ValidationError>)base.GetValue(ValidationErrorsProperty); }
    set { base.SetValue(ValidationErrorsProperty, value); }
}

 

 

Hope this helps you out if you encounter something like this. :-)

 

By the way, another tip, related to this: don’t forget to initialize the collection property in the constructor of your behavior – if you don’t do that, your collection dependency property will be shared across different behavior instances; pretty sure you don’t want that to happen :-)

 

Happy coding!

.NET, General, Presentations and sessions, RealDolmen, Headline »

[18 Feb 2014 | 0 Comments]

As some of you might know, I’m one of the board members of the RealDolmen Microsoft Community, a Belgium-based user group focussing on Microsoft technology.  We regularly organize events that are of course open to everyone, and one of the upcoming events is a session, delivered by myself, on Fluent API design; March 27th, 6pm, at the RealDolmen offices in Kontich (Antwerp/Belgium).  Here’s what you can expect of it:

 

 

Have you ever wondered how those component & framework builders build a fluent API in C#?  In this session you’ll learn how to do this, but we won’t stop there: throughout building this fluent API, we’ll cover various other techniques  – from interfaces over generics to lambda expressions & expressions trees and some reflection.  This is your chance to learn about some of the less touched upon inner workings of framework building & very powerful C# language features.  Make sure you've had enough coffee, because this ain't for the faint of heart ;-)

 

Category: C#, Architecture

 

Level: 400

 

 

If you’re interested, feel free to register via Eventbrite – the event is free! :-)  But be fast, because tickets are very limited. 

.NET, General, Headline »

[6 Jan 2014 | 0 Comments]

Microsoft_MVP_logo_verticalWhen I opened my inbox on January the 1st (admittedly, quite late in the evening due to old years’ eve celebrations :-)) , I was very pleasantly surprised to find a mail from Microsoft, awarding me with the MVP (Most Valuable Professional) award (category Client Development) for 2014!  

 

Of course, I’m very honoured to have received this, and I guess this is a bit of a “THANK YOU!” blog post of an overexcited MS-tech enthusiast (ie: me), but also a promise to try and live up to the award.  The perfect way to start the year, and at the same time a motivation to keep on the community work, courses, conferences et cetera.

 

Best wishes to all of you, and may the new year bring you most (not everything, you have to have something to look forward to for the year after this one ;-)) of what you wish for!

.NET, Featured, MVVM, Headline, Windows 8 »

[9 Sep 2013 | 0 Comments]

The last few months, I’ve been busy working on a Pluralsight course.  As some of you might know, Pluralsight is one of the most respected online IT course providers worldwide, offering a variety of courses on all kinds of IT-related subjects.  The course I authored for them dives into all aspects of Windows Store app performance. 

 

Most people would agree that ensuring your app is performing well is a must – the problem is that there are so many aspects to performance that it’s hard to keep an overview of what you can or should do in which situation or for a specific scenario.  This course tries to solve that by grouping all performance-related aspects & solutions together.  You’ll learn about perception versus reality and PLM, XAML, data, media and file system performance & strategies, using virtualization, using async to your advantage, right up to tooling & analytics. 

 

So, if you’re interested in getting the best performance out of your Windows Store apps: have a look :-)

 

If you wouldn’t happen to have a Pluralsight account, you can sign up for a trial – there’s a huge amount of interesting courses available.

Featured, General, Presentations and sessions, Headline, Windows 8 »

[13 Jun 2013 | 0 Comments]

I’m currently in Oslo, Norway, on one of the best Scandinavian IT conferences: NDC.  I delivered two talks there, one yesterday, one today. 

 

 

Yesterday’s was an introduction to Windows 8 development with XAML & C#.  You can find the code and presentation on my SkyDrive.

 

Today’s was a pretty advanced session on Windows 8 Store App Performance, including but not limited to XAML tips and tricks, UI and data virtualization and Tasks.  You can find the code and presentation for that here.

 

Hope you enjoyed the sessions, and: happy coding! :-)

.NET, General, Presentations and sessions, Windows 8 »

[9 Mar 2013 | 0 Comments]

During the first half of this week I was in Helsinki, Finland, to deliver 2 sessions at Techdays Finland 2013. 

 

The first session was an introduction to Windows 8 development, while the second session dug a bit deeper and uncovered some of the lesser-know, less-obvious culprits you might face during development.


Both sessions are available for download on my SkyDrive, including source code.  Happy coding! :-)

 

Session 1, Introduction: slidedeck, code.

Session 2, Unwrapping the not-so-obvious: slidedeck, code.