ow boy ow boy this is so much fun :)
I get irritated with Value converters because you have to create them in resources and what not... Like me, Dr. WPF hates this as well and he wrote a nice article leveraging MarkupExtensions for this (
http://drwpf.com/blog/2009/03/17/tips-and-tricks-making-value-converters-more-accessible-in-markup/).
Well mix that with MEF and you have something even cooler :)
Basically you define your converter like this
[ExportConverter("BaboonConverter")]
public class BaboonConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return "Baboon";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
And you get that in XAML by doing this
<TextBlock VerticalAlignment="Bottom" Text="{Binding Converter={meffed:MEFedConverter BaboonConverter}}"/>
MEFedConverter is a markup extension that will go look for a Value Converter that is Exported with the name you specify (in the case BaboonConverter).
For now I cheated and leveraged the ViewModelLocator I wrote to create the catalog yet I will refactor the code and make it more sexy :)
So what do you think? Makes sense? I think MEF has loads of potential and that is why I want to build a library that leverages these functionalities....
Its all MEFed up :)
Regards
Marlon
WPF Blog -
http://marlongrech.wordpress.com/Microsoft MVP for Client App