Topics: Actions & Coroutines
Jun 13, 2011 at 9:53 PM
Edited Jun 13, 2011 at 9:54 PM

so I am alittle confused as to why I am getting an error related to these snippets and the handlers not existing... this is in a listbox

xaml snippet

                        <i:EventTrigger EventName="SelectionChanged">
                            <cm:ActionMessage MethodName="ScheduledItemSelected($dataContext)" />

C# snippet

  public void ScheduledItemSelected(Schedule schedule)


those are my code declarations and I have no idea why I get a caliburn error: No target found for method ScheduledItemSelected($eventArgs).  all part of the learning experience for me I guess I don't see what I am doing wrong.

Where as an parameterless methodname works... does it have to do with SelectedItem being bound?

Jun 13, 2011 at 10:07 PM

Is this on a ListBox? $dataContext is probably not correct in this case. There might be a type mismatch happening. It's hard to tell without a little more information.

Jun 13, 2011 at 10:15 PM
Edited Jun 13, 2011 at 10:19 PM

Yes list box bound to a ObservableCollection<Schedule> data is populated from Sterling.


 <ListBox x:Name="scheduledListBox" SelectedItem="{Binding CurrentScheduledItem, Mode=TwoWay}" ItemsSource="{Binding Scheduled}" Height="540" VerticalAlignment="Top">

Jun 14, 2011 at 5:03 AM

so i add the WP7 CM projects to my application so I could step thru to see where it dies... Its coming down to the Target and View both being null, but the context appears to be correct.  The SelectionChangedEventArgs is populated with the selected value.  Got any ideas?

Jun 14, 2011 at 12:47 PM

If this trigger is attached on the ListBox, the the $dataContext will not be the selected item, it will be the VM itself. Perhaps that is causing your problem? There's some sort of mismatch going on. I'm curious as to why you need this trigger? Since you already have the CurrentSheduledItem databound, why not just execute SheduledItemSelected from the setter of that property?

Jun 14, 2011 at 3:38 PM

was trying to do it the CM way with the $dataContext but you're right I can just use the binding with CurrentItemSelected, which does work just fine.  Its just wierd that the action bubbling doesn't work on Wp7 like I expected.

Jun 14, 2011 at 4:47 PM

If you ever get a chance to whip up a simple sample that demonstrates the issue, feel free to send it my way. It's still possible there's a bug somewhere.

Jun 15, 2011 at 3:24 PM

Yea I can when I have a chance... As for the error.. I found that if I drop a parameter markup into the ActionMessage and leave the Method unparameterized it works but the value of the parameter in the method on the viewmodel is null..  But it doesn't error out looking for the methodname.

<cm:ActionMessage MethodName="ScheduleSelectionChanged">
    <cm:Parameter Value="$dataContext" />
</cm:ActionMessage />

Jun 15, 2011 at 3:31 PM

I think you have a type coercion problem. Whatever $dataContext is is not what you think it is. Try changing your method parameter to type object and see what comes through.

Jun 15, 2011 at 4:03 PM
Edited Jun 15, 2011 at 4:04 PM

Ok I think I figured it out... <cm:ActionMessage MethodName="ScheduledItemSelected($eventArgs)" />

Is that the correct format for usage of the ActionMessage?

Does it work slightly different than Message.Attach?  Or are the underlying works related.  I haven't dug this deep yet to find out...  Trying to isolate user implementation error which I think it was on my behalf.  Getting the usage format between ActionMessage and Message.Attach confused.


<cm:ActionMessage MethodName="ScheduleSelectionChanged">
<cm:Parameter Value="$eventArgs" />
</cm:ActionMessage />

returns the correct parameter type to the method with a parameter type of SelectionChangedEventArgs

Jun 15, 2011 at 7:07 PM
Edited Jun 15, 2011 at 7:07 PM

Oh man....I'm sorry I didn't even see your error. It's obvious now. You can't use parameters inside method name, you have to add the parameter elements like you did in your second example. Message.Attach lets you put the whole thing in one string. I'm sorry. The following are equivalent:

<cm:ActionMessage MethodName="ScheduleSelectionChanged">
    <cm:Parameter Value="$eventArgs" />
</cm:ActionMessage />



but the following is an error:

<cm:ActionMessage MethodName="ScheduleSelectionChanged($eventArgs)">

Jun 15, 2011 at 9:28 PM

yeah, I wasn't specific so I was confusing the 2... error corrected, no error in framework :P