[WPF Disciples] More MEF fun :) MEFedValueConverter

125 views
Skip to first unread message

Marlon Grech

unread,
Apr 16, 2010, 3:21:06 PM4/16/10
to wpf-di...@googlegroups.com
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

MEFedMVVMDemoWPFONLY.zip.doc

Sacha Barber

unread,
Apr 16, 2010, 6:34:31 PM4/16/10
to wpf-di...@googlegroups.com
I just like the baboons
--
Sacha Barber
sacha....@gmail.com

Glenn Block

unread,
Apr 16, 2010, 11:30:59 PM4/16/10
to wpf-di...@googlegroups.com
I can officially pass you my MEF Maniac title. I am all meffed out :-)
> --
> Subscription settings:
> http://groups.google.com/group/wpf-disciples/subscribe?hl=en
>

--
Sent from my mobile device

Marlon Grech

unread,
Apr 17, 2010, 1:36:12 AM4/17/10
to wpf-di...@googlegroups.com
@ Sasha Yea Baboon converters are simply awesome !!!!!!

@ Glenn why did you do this to me... MEF is screwing up my social life!!!!


Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/
Microsoft MVP for Client App



Glenn Block

unread,
Apr 17, 2010, 3:14:56 AM4/17/10
to wpf-di...@googlegroups.com
So I could reclaim mine :-)

Marlon Grech

unread,
Apr 17, 2010, 3:18:12 AM4/17/10
to wpf-di...@googlegroups.com
haha you might try but I assure you its impossible to get it back! I am screwed for life because of programming but hey, so are you :) and all the rest I guess...

the trick is never share with non geeks things like, "yesterday I spent a night having so much fun coding"; just removing "coding" from the end of the sentence and people think its cool

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/
Microsoft MVP for Client App



Reply all
Reply to author
Forward
0 new messages