0

I'm trying to create an action for an attached event which I don't think CM supports out of the box.

This question/answer shows how to do this

using attached events with caliburn micro Message.Attach

but it requires using the long CM ActionMessage syntax, however, when I try to do this I get an 'ActionMessage does not exist in the XML namespace ' where blah is the CM namespace.

All of the examples also show this syntax; at the moment I've just put the code into the view which casts the DataContext to the ViewModel type and calls the appropriate method (I don't like this approach though as it couples the view to the VM and it's inconsistent with the rest of the app)

Anyone have any ideas why I can't see the ActionMessage?

e.g.

<i:Interaction.Triggers> 
                <Helpers:RoutedEventTrigger RoutedEvent="Helpers:DataChanging.Changing"> 
                    <!-- this line throws the error -->
                    <cal:ActionMessage MethodName="SelectedDataChanged"> 
                        <cal:Parameter Value="$eventargs" /> 
                    </cal:ActionMessage> 
                </Helpers:RoutedEventTrigger> 
 </i:Interaction.Triggers> 

I'm using SL5 and CM's SL5 assembly but no joy...

Interestingly, if I try to use 'ActionMessage' elsewhere it seems to be resolved correctly but of course it's not very useful outside of where I want it!

Update:

This is the view namespace def

xmlns:cal="http://www.caliburnproject.org"

I've tried the actual assembly qualified namespace and other combinations, all with the same issue

Community
  • 1
  • 1
Charleh
  • 13,749
  • 3
  • 37
  • 57
  • Can you maybe post somewhere your exact view code which throws the exception? – nemesv Sep 08 '12 at 11:47
  • I just did - it's in the question, I copied the code from the example on the other question, I get a design time error and the app wont build because of it - look at the example XAML, I've put a comment where the design time error is thrown – Charleh Sep 08 '12 at 12:16
  • @Charleh Need to see the full definition of the view, the declaration of the cal namespace is likely the problem. – Simon Fox Sep 16 '12 at 22:27
  • I don't think it's that, check my update - I don't think I'd be able to see all the other CM stuff if the xmlns declaration wasn't working – Charleh Sep 18 '12 at 09:11
  • @Charleh, how did you solve this issue? I am facing exactly same issue – Jayakrishnan Mar 12 '19 at 06:16
  • 6 years ago... that's a good question! Can't even remember what I had for breakfast yesterday... – Charleh Mar 12 '19 at 15:43

2 Answers2

1

I've never had to use the ActionMessage syntax before, but as long as the control has an event that you're trying to attach to have you tried the following syntax:

<Button Content="Remove" cal:Message.Attach="[Event Click] = [Action Remove($dataContext)]" />

I've been able to use that on a wide variety of controls without any issues.

http://devlicio.us/blogs/rob_eisenberg/archive/2010/07/17/caliburn-micro-soup-to-nuts-pt-3-all-about-actions.aspx

Jason Massey
  • 1,088
  • 10
  • 18
  • 1
    Unfortunately it's an attached event, the control doesn't actually own the event so CM can't subscribe to it in the traditional way. I'm stuck with code in the view at the moment – Charleh Sep 11 '12 at 09:57
0

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

<i:Interaction.Triggers> 
    <Helpers:RoutedEventTrigger RoutedEvent="Helpers:DataChanging.Changing">
        <cal:Action.Target>
            <cal:ActionMessage MethodName="SelectedDataChanged">
                <cal:Parameter Value="$eventargs"/>
            </cal:ActionMessage>
        </cal:Action.Target>
    </Helpers:RoutedEventTrigger RoutedEvent="Helpers:DataChanging.Changing">
</i:Interaction.Triggers>
JTIM
  • 2,774
  • 1
  • 34
  • 74