multiple csla:InvokeMethods on a control

multiple csla:InvokeMethods on a control

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


Martino posted on Friday, February 19, 2010

This might be more of a WPF question, but is it possible to set multiple csla:InvokeMethods on one control?

for example a csla:InvokeMethod.TriggerEvent for  the click event and one for the MouseEnter event of a button?

This obviously won't work

<Button

csla:InvokeMethod.TriggerEvent="Click"

csla:InvokeMethod.MethodName = "OnClickHandler"

csla:invokeMethod.TriggerEvent="MouseEnter"

csla:InvokeMethod.MethodName = "OnMouseEnterHandler"/>

 

I've also seen some refernces made to a MVVM example, is this the MVVMExperiment project? If not where do i find the MVVM example?

 

btw. Love the new modelview stuff in 3.8.0

 

Martino replied on Tuesday, February 23, 2010

Any ideas?

triplea replied on Tuesday, February 23, 2010

I remember a similar post but even though I searched for it I could not find it.

I think the only way to achieve this you will need to use the trigger method:

<Button Content="Click Me">
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="Click">
      <csla:Execute MethodName="LoadData" />
    </i:EventTrigger> 
    <i:EventTrigger EventName="MouseOver">
      <csla:Execute MethodName="AnimateMe" />
    </i:EventTrigger> 
   ...
  </i:Interaction.Triggers>
</Button>

I know this is not exactly what you are looking for but thought I'd let you know anyway.

Martino replied on Tuesday, February 23, 2010

This would work in most cases.

In my case I need to databind to the (non-bindable) SelectedItems for both triggers. For that i'd like to use Rockys work around:

csla:InvokeMethod.MethodParameter="{Binding ElementName=myGrid, Path=SelectedItems}"

with a dependency property 'SelectedItems' in the ViewModel

I've looked at using multibinding, but i'm kinda stuck there too.

 

Martino replied on Thursday, February 25, 2010

Just in case somebody ran into the same issue. Here is Rockys response:

Unfortunately InvokeMethod is an attached property (actually a set of related attached properties), so there’s no real way to have more than one of them attached to a control – at least not that I know of.

 Execute is a trigger action based on the event trigger concepts defined by Blend 3 in their SDK. They don’t expose as much information to a trigger action as I can get as an attached property, which restricts what Execute can do to solve this problem. In short, Execute can’t do the “live binding” that InvokeMethod does, because trigger actions just don’t have enough information to do that.

 In CSLA 4 I’ve implemented yet another solution, called TriggerAction. This is a standalone control, which is required to work with the Visual Studio 2010 designer.

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

 Right now it doesn’t do the “live binding” that InvokeMethod does either. But I suppose it probably should include that functionality.

 The advantage of TriggerAction, is that you can have as many of them as you’d like, all attached to different (or even the same) events of a given UI control. So the flexibility is substantially greater than with InvokeMethod.

 You can see the code here

http://www.lhotka.net/cslacvs/viewvc.cgi/core/branches/V4-0-0-RC/Source/Csla.Xaml/TriggerAction.cs?view=markup

 But as I said, the MethodParameter functionality from InvokeMethod needs to be merged into this control for it to fully address your scenario.

Rocky

Copyright (c) Marimer LLC