Silverlight Feeds - All your Silverlight feeds in one place.

Sponsors

Thursday, August 06, 2009

Expression Blend Samples InvokeDataCommand bug

by Laurent Bugnion via Silverlight on 8/6/2009 6:21:52 PM

My good friend and super hero programmer Pete Blois posted an impressive collection of samples using and extending Expression Blend behaviors and triggers on Codeplex some time ago. There are a few real treasures in there, and some of them that I would like to integrate in my MVVM Light toolkit, thus avoiding to reinvent the wheel. I am still checking the license (the Samples use the MS-PL license) but I think it should work just fine.

One feature in particular that I find super helpful is InvokeDataCommand. This Trigger allows any event to be bound to a command, for example an ICommand or a RelayCommand. In the moment, if you use the MVVM Light toolkit, you need a few lines in the code behind to handle the event and relay to the corresponding RelayCommand on the ViewModel. No big deal, but InvokeDataCommand is in XAML only, and this can even be done in Blend, so it is even easier for visual people (designers, integrators…). With InvokeDataCommand, the code looks like this:

<Button Content="Click me">
    <si:Interaction.Triggers>
        <si:EventTrigger EventName="Click">
           <i:InvokeDataCommand Command="{Binding ClickCommand}" />
        </si:EventTrigger>
        <si:EventTrigger EventName="MouseEnter">
            <i:InvokeDataCommand Command="{Binding MouseOverCommand}" />
        </si:EventTrigger>
    </si:Interaction.Triggers>
</Button>

However, as described here, there seems to be a bug in InvokeDataCommand which prevents it to work in WPF. The code above works fine in Silverlight, but fails in WPF. I downloaded the projects and took a look at the code, and thanfully the bug was not too hard to spot. In Silverlight, to work around the limitation that bindings can only be applied on FrameworkElements, a BindingListener class has been used. However, this class is not needed in WPF, and in fact it causes the bug (note that in the contrary of what is described in the bug report, I do not witness any exception, the code des’t crash but it will just fail).

I submitted a corrected version of InvokeDataCommand.cs on the Codeplex site, and hope it will be reviewed and integrated soon. In the mean time, feel free to contact me if you need details about the fix.

The issue in Codeplex can be seen here.

email it!bookmark it!digg it!

Original Post: Expression Blend Samples InvokeDataCommand bug

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us