Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caliburn.Micro Action with parameter not binding

I have a textbox with the following:

<i:Interaction.Triggers>
 <i:EventTrigger EventName="KeyUp" >                                               
     <cal:ActionMessage MethodName="OnKeyUp" >
          <cal:Parameter Value="$eventArgs"/>
     </cal:ActionMessage>
 </i:EventTrigger>

If I run this, an error message is produced saying "No target found for Method OnKeyUp." If I remove the parameter from the message, and the method, then it runs fine.

This is the method.

public void OnKeyUp(object sender, KeyEventArgs e) {
        MessageBox.Show(e.Key.ToString());
    }

I don't see what the issue is.

like image 977
Greg Gum Avatar asked Apr 27 '13 17:04

Greg Gum


1 Answers

Your view model method takes two parameters, but you're only passing one.

Either change your view to pass the $source:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="KeyUp">
        <cal:ActionMessage MethodName="OnKeyUp" >
           <cal:Parameter Value="$source" />
           <cal:Parameter Value="$eventArgs" />
        </cal:ActionMessage>
    </i:EventTrigger>
</i:Interaction.Triggers>

or change your method to just take the event arguments:

public void OnKeyUp(KeyEventArgs e) { ... }

You could also use the much nicer shorthand:

<TextBox cal:Message.Attach="[Event KeyUp] = [Action OnKeyUp($source, $eventArgs)]" />
like image 62
devdigital Avatar answered Oct 16 '22 02:10

devdigital