Golden Nuggets

Wednesday, December 16, 2009

So now I'm a published author.

Well, not *EXACTLY*!

My MSDN Flash article “Getting started with MEF” made the grade and was included in the “MSDN Flash eBook of the best 13 technical articles of 2009”.

Thanks to Eric Nelson for including me – I’m well chuffed. Now to write some more!

Get it: http://blogs.msdn.com/ericnel/archive/2009/12/16/free-msdn-flash-ebook-of-the-best-13-technical-articles-of-2009.aspx


Friday, November 13, 2009

Friday Quickie: The *other* TemplateBinding syntax

Setting up the template for a new custom control in Silverlight is fraught at the best of times – the Silverlight runtime invariably swallows any error in the template and gives just a cryptic exception.

But stranger still is a limitation on how the {TemplateBinding ...} syntax can be used and the exception that is thrown when in error.

The {TemplateBinding ...} syntax provides a quick and simple way to bind properties within a control’s template to the properties of the control itself. According to the MSDN documentation, it’s a shortcut to the more full-featured {Binding ...} syntax. But what’s not clear from the documentation is that {TemplateBinding ...} can only bind a control property to a DependencyProperty on the control class.

If you try and use {TemplateBinding ...} against a normal property on the control, you get the strange exception shown right – confusing because the target control (WizardActionButton in the example) absolutely does have a State property.

The solution is to use the {Binding ...} syntax where the source property isn’t a DependencyProperty, and to use the {RelativeSource ...} syntax to specify that you’re actually binding to the control within its template.

Wrong:

<i4tControls:WizardActionButton x:Name="RetreatButtonPart"

Style="{StaticResource ActionButtonStyle}"

State="{TemplateBinding CanRetreat}"

Content="{TemplateBinding RetreatButtonContent}"

ContentTemplate="{TemplateBinding RetreatButtonContentTemplate}"

/>

Correct:

<i4tControls:WizardActionButton x:Name="RetreatButtonPart"

Style="{StaticResource ActionButtonStyle}"

State="{Binding Path=CanRetreat,RelativeSource={RelativeSource TemplatedParent}}"

Content="{TemplateBinding RetreatButtonContent}"

ContentTemplate="{TemplateBinding RetreatButtonContentTemplate}"

/>

Labels: ,

Monday, September 14, 2009

Cometh The Gu

This should be old news to most readers (it was announced all of 3 days ago!), but bears re-posting.

Scott Guthrie is presenting in Manchester
on 29th September!

Why haven’t you registered already?

Gu’dness: http://developerdeveloperdeveloper.com/guathon/Default.aspx

Wednesday, September 09, 2009

Wednesday Quickie: Forcing event un-subscription

This is another really simple and obvious code snippet, but one well worth remembering – posted this morning by Fabrice MARGUERIE.

The crux is that event subscriptions can cause memory leaks – so ensuring they are un-subscribed is essential. The code snippet is designed to be used in the Dispose or Cleanup method on the publishing object, and forcibly disconnects any subscribers just before the publishing object is disposed.

if (SomeEvent != null)
{
foreach (EventHandler handler in SomeEvent.GetInvocationList())
SomeEvent -= handler;
}

Simple. Clean. Elegant. Use it!

Force your subscribers away: http://weblogs.asp.net/fmarguerie/archive/2009/09/09/forcing-event-unsubscription.aspx

Labels: , ,

Wednesday, August 05, 2009

Wednesday Quickie: Why Rounded Corners Work...

Came across this little article this afternoon via a tweet from @DaveSussman giving some background and justification for using rounded corners in your UI design. Well worth a read - I particularly like the examination of Apple hardware from a rounded corner point of view.

Round your rectangles: http://www.uiandus.com/2009/07/27/theories/realizations-of-rounded-rectangles/

Labels: ,

Wednesday Tidbit: Smoooooooth scrolling a ScrollViewer

Spotted this great little article today on how to use the Mediator pattern to allow you to bind an animation to a scroll-viewer to get really slick scrolling.

Smooth as butter on a muffin: http://blogs.msdn.com/delay/archive/2009/08/04/scrolling-so-smooth-like-the-butter-on-a-muffin-how-to-animate-the-horizontal-verticaloffset-properties-of-a-scrollviewer.aspx

Monday, August 03, 2009

Monday Quickie: CSS Resources

This morning, @DaveSussman (http://blogs.ipona.com/davids) posted a link on Twitter to an excellent set of CSS resources:

http://is.gd/20qgs

This post is just an aide-memoire... and to share the CSS goodness.

Thursday, June 11, 2009

Thursday Quickie: Using the NULL pattern for event delegates

This little tweet turned up this morning in response to Mike Taulty wanting“the ability to fire an event without having to check it for null”.

richardblewett @mtaulty you can use the null pattern for this Mike, just do = delegate{}; on the event declaration
Thu, Jun 11 09:27:36 from Witty in reply to mtaulty


It’s pretty obvious when you think about it tho’...

public event EventHandler CriteriaChanged = delegate{};

Easy-peasey.

Update: Richard credits Andy Clymer the original idea (see comments). How far will the chain go?!

Labels: , ,