InvokeMethod vs. Execute

InvokeMethod vs. Execute

Old forum URL: forums.lhotka.net/forums/t/8178.aspx


lukky posted on Thursday, December 17, 2009

Hi Rocky,

In this post:

http://www.lhotka.net/weblog/CSLANET38Beta2MVVMSupport.aspx

you mention the following:

"The advantage of using InvokeMethod is that it has several options around data binding that simply aren’t available to a trigger action like Execute. Most notably, InvokeMethod has a MethodParameter property that can be bound using a binding expression – so it can pull values from other UI controls, resources, the DataContext, etc. There’s no way to do this with a trigger action like Execute."

I'm a bit confused. I'm looking at the source code for Csla.Wpf.Execute, and there IS a MethodParameter property on that class.

Did you mean that there was no such parameter (at the time you posted), or did you mean that Invoke.MethodParameter can't be bound using a binding expression ?

Also, are these classes ready for production code ? I'm starting to move away from Windows Forms, and would like to learn more about Wpf, MVVM, Prism and how CSLA.NET fits in between. Do you have any formal documentation yet on the different Wpf UI support classes ?

Thanks

RockfordLhotka replied on Thursday, December 17, 2009

There is a MethodParameter on both types. But you can't use a binding expression with Execute because of the way the XAML is nested. Or at least I couldn't figure out a way to write valid XAML that included a binding expression inwide the trigger action.

The only "docs" for the XAML stuff is in the CSLA .NET for Silverlight video series. As soon as I finish the Core 3.8 video series I'll do a WPF video that walks through the various CSLA components specifically designed for WPF.

lukky replied on Thursday, December 17, 2009

That WPF video is good news !

I'm probably out of my league here as I really don't have a good understanding of WPF binding expressions yet, but it seems to me that the Execute's MethodParameter is capable of handling binding expressions.

In the MVVMexperiment project, in the ListPage.xaml, there is a "Process Items" button. I've simply created a copy of it on the same page, and now I have the following XAML:




<Button Content="Process items" Tag="{Binding ElementName=DataListBox}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<csla:Execute MethodName="ProcessItems2" MethodParameter="{Binding ElementName=DataListBox, Path=SelectedItems}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button Content="Process items" Tag="{Binding ElementName=DataListBox}"
csla:InvokeMethod.TriggerEvent="Click"
csla:InvokeMethod.MethodName="ProcessItems2"
csla:InvokeMethod.MethodParameter="{Binding ElementName=DataListBox, Path=SelectedItems}">
</Button>

So, one button is calling the ProcessItems2 method by using an InvokeMethod, and the other one using Execute, and in both case I can pass the SelectedItems using a binding expression.

Is this a too simple use case, or is it typical of what one will have to do to call methods on the VM ?

That's on Windows 7 + VS2010 beta 2.

Thanks

(waiting for the WPF video...)

RockfordLhotka replied on Thursday, December 17, 2009

It may be that WPF 4 allows binding to properties of a trigger action. I was unable to use binding in SL3/WPF3.5.

 

lukky replied on Thursday, December 17, 2009

That's great news then :-)

Copyright (c) Marimer LLC