0

I want to use the Prism EventTrigger by invoking the command action but there is an error in higher versions of visual studio especially .Net Framework 4.0 and higher. What updates have been made in the prism library to address this issue? I'm unable to use the InvokeCommandAction to invoke a command that has been bonded to the ViewModel. Below is a code snippet and a screenshot of the error message.

<igwpf:OutlookBarGroup  x:Class="PrismOutlook.Modules.Mail.Menus.MailGroup"
             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:local="clr-namespace:PrismOutlook.Modules.Mail.Menus"
             xmlns:ig="http://schemas.infragistics.com/xaml"
             xmlns:igwpf="http://schemas.infragistics.com/xaml/wpf"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             Header="Mail">
    <Grid>
        <ig:XamDataTree ItemsSource="{Binding Items}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="ActivaeNodeChanged">
                    <prism:InvokeCommandAction Command="{Binding SelectedCommand}" TriggerParameterPath="NewActiveTreeNode.Data" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
                <ig:XamDataTree.GlobalNodeLayouts>
                <ig:NodeLayout Key="GlobalLayout" TargetTypeName="NavigationItem" DisplayMemberPath="Caption"/>
            </ig:XamDataTree.GlobalNodeLayouts>
        </ig:XamDataTree>
    </Grid>
</igwpf:OutlookBarGroup>

Her is the error message i see in the solution output.

Screenshot of error message

I'm new to Prism but have quite a good experience with WPF and MVVM framework. Actually I'm following a Youtube Tutorial By Brian Lagunas and I realized it's an old tutorial and possibly some modifications in the Prism source code and build, there are compatibility issues. I'm using Visual studio 2019, Project configuration is .NetFramework 4.7.2 and the prism version currently installed is version 7.2.0.1422.

Thank you in advance for the assistance in resolving this issue.

thatguy
  • 21,059
  • 6
  • 30
  • 40
Sinado123
  • 93
  • 2
  • 6

2 Answers2

0

Xaml Behaviors are now a nuget package.

As per: https://devblogs.microsoft.com/dotnet/open-sourcing-xaml-behaviors-for-wpf/

Steps to migrate:

Remove reference to “Microsoft.Expression.Interactions” and “System.Windows.Interactivity” Install the “Microsoft.Xaml.Behaviors.Wpf” NuGet package. XAML files – replace the xmlns namespaces “http://schemas.microsoft.com/expression/2010/interactivity” >and “http://schemas.microsoft.com/expression/2010/interactions“with “http://schemas.microsoft.com/xaml/behaviors“ C# files – replace the usings in c# files “Microsoft.Xaml.Interactivity” and “Microsoft.Xaml.Interactions” with “Microsoft.Xaml.Behaviors”

Your eventtrigger must also be a routed event that is not already handled elsewhere.

https://learn.microsoft.com/en-us/dotnet/api/system.windows.eventtrigger?view=netcore-3.1

Andy
  • 11,864
  • 2
  • 17
  • 20
0

This does not seem to be an issue of Prism, but the Blend SDK libraries. Your code should work just fine, since InvokeCommandAction derives from TriggerAction<T> in System.Windows.Interactivity and version 7.2.0.1422 does not use an old version of it.

There were similar issues in the past that were not caused by the implementation of Prism, but presumably SDK libraries that were not registered correctly. See this issue for reference and solutions from Prism 5.0 and 6.0. What seems to work in this case is registering the new version of the library manually to the global assembly cache. There is also a related post on this issue.

gacutil -i "C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.5\Libraries\System.Windows.Interactivity.dll"

Another option mentioned in the related post is to use the Microsoft.Xaml.Behaviors.Wpf NuGet package instead of System.Windows.Interactivity. Although I recommend you to use it where you can, it will trigger another warning when used with Prism's InvokeCommandAction, so you should probably upgrade to this solution once a new version of Prism bases its types on this new package.

Invalid type: expected type is 'TriggerAction', actual type is 'InvokeCommandAction'

thatguy
  • 21,059
  • 6
  • 30
  • 40