Wednesday, January 13, 2010

Using PostSharp 1.5 to automate INotifyPropertyChanged

I've spent some time today working with PostSharp for Silverlight, trying to use it to simplify implementing the INotifyPropertyChanged interface on my view models. Ultimately I hope to also simplify doing change notification via Prism's Event Aggregator too.

Unfortunately, as nice a solution as this appears to be, I will probably be throwing it away. The view model below works fine when databound:

[NotifyPropertyChanged]
public class MyViewModel
{
...
public int Age
{
get;
set;
}
...
}

However, this one breaks databinding - no change notification works at all:

[NotifyPropertyChanged]
public class MyBaseViewModel
{
...
}

public class MyViewModel
{
...
public int Age
{
get;
set;
}
...
}

So next I think I'll be looking at using Castle Dynamic Proxy to do it for me. Jonas Follesoe has been discussing it recently. What's extra nice is that he's also dealt with dependent properties too.

No comments:

Post a Comment