Issue with EventToCommand in VS2012 (Update2)

Apr 16, 2013 at 3:43 PM
Edited Apr 16, 2013 at 3:45 PM
Hi,

I'm using the latest build of MVVM Light, we use a mixture of Prism and MVVM Light as we much prefer the RelayCommand in MVVM Light, the superb Messenger and the EventToCommand behavior for binding to our VM's. Prism is mainly used for modularity and region management. The project is VS2012 (Updated2), win7 64bit, .NET4.5 & Telerik Rad Controls.

I'm using the following libs:

GalaSoft.MvvmLight.Extras.WPF45 (v4.0.30319) (via nuget today)
GalaSoft.MvvmLight.WPF45 (v4.0.30319)
System.Windows.Interactivity (v4.0.30319)

Prism 4.1.0.0

In this particular view, Prism is not used so that can be disregarded as the Shell has a ViewModelLocator.

The markup is as follows:
<UserControl x:Class="Company.Framework.Shell.View.StatusBar"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:commands="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF45"
             DataContext="{Binding Source={StaticResource Locator}, Path=StatusBar}"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Company.Framework.Resource;Component/SharedResources.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    
    <Grid>
        <StatusBar DockPanel.Dock="Bottom">

            <StatusBarItem DockPanel.Dock="Left">
                {server}
            </StatusBarItem>

            <Separator DockPanel.Dock="Left" />

            <StatusBarItem DockPanel.Dock="Left">
                {database}
            </StatusBarItem>

            <Separator DockPanel.Dock="Left" />

            <StatusBarItem DockPanel.Dock="Left">
                {user}
            </StatusBarItem>

            <Separator DockPanel.Dock="Left" />

            <StatusBarItem DockPanel.Dock="Left">
                {office}
            </StatusBarItem>

            <!-- Last item is docked in center, as usual. -->
            <StatusBarItem HorizontalAlignment="Center">
            </StatusBarItem>

            <!-- Define quick module preview button -->
            <Separator DockPanel.Dock="Left" />
            <StatusBarItem HorizontalAlignment="Right">
                <telerik:RadRibbonToggleButton  Name="radradiobutton_titlebartoggle" 
                                                    Padding="1"
                                                    Width="18" 
                                                    Height="18" 
                                                    Margin="0,0,10,0"
                                                    SmallImage="{StaticResource statusbar_toogle_quickview_16x16}"
                                                    IsChecked="True"
                                                    ToolTip="Show or hide the module quick access area">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Checked">
                            <commands:EventToCommand Command="{Binding ToogleCommand}" CommandParameter="{Binding ElementName=radradiobutton_titlebartoggle, Path=IsChecked}" />
                                </i:EventTrigger>
                            <i:EventTrigger EventName="Unchecked">
                                <commands:EventToCommand Command="{Binding ToogleCommand}" CommandParameter="{Binding ElementName=radradiobutton_titlebartoggle, Path=IsChecked}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    
                </telerik:RadRibbonToggleButton>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</UserControl>
The EventToCommand behavior works as expected but I'm getting an unstable environment in the XAML designer. I have the view open and the following error is reported but it compiles ok:
Error   1   Cannot create an instance of "TriggerActionCollection". D:\TFS\Company.Framework\Source\Company.Framework.Shell\View\StatusBar.xaml 63  29  VShips.Framework.Shell
Any ideas what's causing this behaviour?

Thanks,

Taz.

(ps: thanks for a great framework)
May 7, 2013 at 9:35 AM
Any ideas on this one?
Jul 15, 2013 at 1:42 PM
Bump. Experiencing the same issue.
Jul 15, 2013 at 1:46 PM
cswimmer wrote:
Bump. Experiencing the same issue.
At least it's not just me. The app compiles ok but it's a problem as the more junior team members see the compile error and assume there's an issue.
Coordinator
Jul 21, 2013 at 12:07 PM
Hi,

Typically these issues are caused by an old version of the System.Windows.Interactivity.dll. Unfortunately, because this DLL gets installed by the Blend SDK, it is possible that Visual Studio replaces the reference to this DLL in your application with the one that was installed with Blend. It is very important to make sure that you always use the latest version of this DLL otherwise the application will work but the design time experience will get impacted negatively.

Thanks
Laurent
Jul 22, 2013 at 8:49 AM
Edited Jul 22, 2013 at 10:09 AM
Hi Laurent,

Thanks for your reply.

I appear to have three versions of this library on my machine (Win7 x64).

3.5.0.0
4.0.0.0
4.5.0.0

My project appears to be pointing at the 4.0.0.0 library.

I take it 4.5.0.0 is the correct one to use with the MVVM Light WPF45 libraries?

Thanks,
Norman.

EDIT:

4.5.0.0 seems to resolve the issue (C:\Program Files (x86)\Laurent Bugnion (GalaSoft)\Mvvm Light Toolkit\Binaries\WPF45\System.Windows.Interactivity.dll) v4.0.30319
Coordinator
Jul 22, 2013 at 6:59 PM
Hi,

Happy that it solved the issue. Normally I distribute the latest version of this DLL, but if you have an earlier version of the Blend SDK installed, it is possible that Studio redirects the reference to the installed version, even if it is not as recent. It is a real PITA and I have talked to the Blend team about this, I hope that they stop increasing version numbers and/or giving strong names to that assembly.

Note that the version number is not directly related to ,NET 4.0 vs 4.5 but rather VS10 vs VS12 (eg Blend 4 vs Blend 5).

Cheers
Laurent