FoioLag
FoioLag

Reputation: 59

I can't use ActionMessage from caliburn micro, how do I resolve it?

From what I read in the description of Caliburn Micro, this code should be compiled without problems. Caliburn Description

<Button>
<i:Interaction.Triggers>
    <i:EventTrigger EventName="Click">           
        <cal:ActionMessage MethodName="AbrirPDF">
            <cal:Parameter Value="{Binding CNPJ}"/>
        </cal:ActionMessage>            
    </i:EventTrigger>        
</i:Interaction.Triggers>   
</Button>

When trying this, I get the following error:

ArgumentException: Cannot add instance of type 'ActionMessage' to a collection of type 'TriggerActionCollection'. Only items of type 'T' are allowed.

Could someone help me solve this problem?

Upvotes: 0

Views: 641

Answers (3)

Darren Gosbell
Darren Gosbell

Reputation: 1940

For Caliburn.Micro v4 I found that changing the namespaces to the following fixed my issue and I did not have to add the extra <cal:Action.Target> tags

xmlns:cal="http://caliburnmicro.com"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"

Previously I had been using the following namespaces

xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro.Platform"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

Upvotes: 1

JTIM
JTIM

Reputation: 2771

I had similar issues I had to add an extra xaml tag before calling ActionMessage my corresponding sample to get it to work was:

<StackPanel>
    <Button>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
                <cal:Action.Target>
                    <cal:ActionMessage MethodName="AbrirPDF">
                        <cal:Parameter Value="{Binding CNPJ}"/>
                    </cal:ActionMessage>
                </cal:Action.Target>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Button>
</StackPanel>

Then I was able to access the specified tag.

Upvotes: 2

mm8
mm8

Reputation: 169200

You probably have the wrong namespace mappings. This should compile:

<UserControl x:Class="CaliburnMicroSample.Views.ShellView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:cal="http://www.caliburnproject.org">
    <StackPanel>
        <Button>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <cal:ActionMessage MethodName="AbrirPDF">
                        <cal:Parameter Value="{Binding CNPJ}"/>
                    </cal:ActionMessage>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>
    </StackPanel>
</UserControl>

The only installed NuGet package is Caliburn.Micro 3.2.0.

Upvotes: 2

Related Questions