Screen conductor and action tunneling

Apr 27, 2011 at 11:48 AM
Edited Apr 27, 2011 at 11:49 AM

Hi all,

Let's suppose we have a main ViewModel with some UI button to execute some command, ie "Save". CM automatically wire this command on the Save(), CanSave() functions when present. If the main view model is a Conductor<T>.Collection.OneActive, and the Save(),CanSave() is implemented on the child viewmodel, is it possible to automatically wire the execution/availability update on the *active* child view model ?



Apr 27, 2011 at 12:18 PM

I suppose you just need to bind the Action.Target or Action.TargetWithoutContext to the Conductor<T>.ActiveItem

     <Button x:Name="Save" cm:Action.TargetWithoutContext="{Binding Path=ActiveItem}"/>

Apr 27, 2011 at 1:22 PM

Thanks BladeWise,

Your reply seems the right way to go. Unfortunately, even if caliburn log that the action is correctly bound to my model, event is not fired. Do the naminc convention works even if I change the target ?

Apr 27, 2011 at 1:51 PM

Uhmmm... I'm checking CM sources right now and, as far as I can see, updating the Target or the TargetWithoutContext should trigger an ActionMessage.UpdateContext.

If I am not wrong, the naming convention does not specify a Target (which, by default, is the DataContext), so everything should work fine... could you try to avoid the naming convention and set the message directly?

     <Button cm:Message.Attach="[Event Click] = [Action Save()]"
             cm:Action.TargetWithoutContext="{Binding Path=ActiveItem}"/>

Apr 27, 2011 at 1:59 PM

Thanks BladeWise,

By specifying the message directly, as you show, it works perfectly. Is this the way to go or am I missing something ? Ie the convention that bounds action trigger to function ( ie Buttox x:Name=Save with function Save() ) does not work by design if we retarget the action ?

Apr 27, 2011 at 2:32 PM

The ViewModelBinder uses Message.Attach to build the EventTrigger\ActionMessage, so there should be absolutely no difference... moreover, as I guessed, there is no assumption over the Target, in the naming convention.

Can you upload a simple repro of your issue?

Apr 27, 2011 at 2:59 PM

Yep I didi it here:

Apr 27, 2011 at 4:24 PM

As I stated in the work item comment, the problem is that I gave you a bad advice in my first post!

The naming convention for Actions will try to associate elements in the view with methods defined in the associated view-model; since no Save method is defined there, no convention is applied, and thus no ActionMessage is created. That said, even setting the Target has no meaning (there is no Action needing a target).

The second code snippet I provided is indeed the answer: you must specify both the target and the Action, since you cannot rely on the convention.

My bad for not paying enough attention --'

Apr 27, 2011 at 5:10 PM

#BladWise thanks for the great help, no reason for apologize, is just me that I need to get deeper in the code to have such things obvious :)