Action bubbling does not work if you use convention?

Topics: Actions & Coroutines, Conventions
Jan 23, 2012 at 11:02 AM

Hello All,


This question is about action bubbling from a child control to its parent control.

The viewmodel of the parent contains MethodA

ParentViewModel.cs
public void MethodA() { }

In the child control I have a button that when click needs to fire this MethodA on the parrent.

The action is bubbled if I'm explicit and us a Message.Attach:

<Button cal:Message.Attach="MethodA">Check Explicitly</Button>

So I have a working scenario.

However, isn't this suppose to work as well when you rely on the convention that the name of the control corresponds to the click event like so ?
<Button x:Name="MethodA">Check Explicitly</Button>

 

I don't know if this is a bug or...  by design



Jan 23, 2012 at 1:34 PM

Convention don't work if your ParentControl is a non standard wpf control, because CM doesn't know how to inspect it. See http://caliburnmicro.codeplex.com/discussions/286993

Jan 23, 2012 at 2:48 PM

Hello Kmees,

That makes sense but it _is_ a standard control.. The Parent is a System.Windows.Window and the usercontrol is embeded as a ContentControl because thats the way Caliburn likes it I believe

<!-- Parent -->

<Window   

x:Class="ShellView" ...

<!-- Child -->

        <ContentControl            x:Name="ChildControl" />            

 

Kind Regards, Tom                                    

Coordinator
Jan 23, 2012 at 7:15 PM

No. Action Bubbling does not work by convention because we have no way to identify the convention. Because the ViewModel being bound does not container the method which can be matched to the control, we pass over the named control. There's no way to know that that control should bubble an action.

Jan 24, 2012 at 8:24 AM
Edited Jan 24, 2012 at 8:24 AM

Hello Rob,

Thanks for taking the time my question. Since this is the first time we write I'd like to thank you for this very good framework (which should be rewarded by a title like MVP BTW ;)


Allow me to dissect your sentences since I would like to get some deeper knowledge about CM


"No. Action Bubbling does not work by convention because we have no way to identify the convention. "


Can you go a bit deeper here? Clearly,  there is a way to identify the convention if you use the following syntax<Button cal:Message.Attach="MethodA">Click</Button> (first notation)
But there isn't when you use this syntax <Button x:Name="MethodA">Click</Button> (second notation)
A good question to ask then is what is the difference between the 2 syntaxes and what do we give up when we wish to use the second notation?Or, what do we gain by using the first?

"Because the ViewModel being bound does not container the method which can be matched to the control, we pass over the named control.There's no way to know that that control should bubble an action."


Now that makes me think that if we use the the second notation then you communicate to CM that you expect the handler to be in the viewmodel to which the control is bound.What does CM prevent to bubble it by default even though it's possible that there is no handler? 

*Is it for performance reasons that the second nation doesn't bubble up the message?*

Regards, Tom