Silverlight RemoveItem

Silverlight RemoveItem

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


wjcomeaux posted on Thursday, June 17, 2010

Hello all.

I'm currently writing a silverlight test application to run some tests for changes being bade to CodeSmith templates for CSLA 4 and Silverlight 4. I've got a basic grid bound and loaded against the PetShop..Product table (for those familiar with the CodeSmith test schema).

I can edit rows in the table just fine, but I'm having trouble with deleting items. What worked in SL3 with previous versions if CSLA was the code almost exactly from the Rolodex example.

 <data:DataGridTemplateColumn>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="DeleteProduct" Content="Delete"
csla:InvokeMethod.MethodName="RemoveItem"
csla:InvokeMethod.Target="{StaticResource ProductListData}"
csla:InvokeMethod.TriggerEvent="Click"
csla:InvokeMethod.MethodParameter="{Binding}"
IsEnabled="{Binding Source={StaticResource ProductListData}, Path=CanRemoveItem, Mode=OneWay}"/>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>

With the current version of Silverlight and CSLA I am getting an odd error: "Method to be executed must have 0 or 2 parameters"
Stacktrace:
   at Csla.Xaml.InvokeMethod.CallMethod(Object sender, EventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

A while back someone else posted what looked like the same issue but never got a response. Any idea what causes this error? I've tried various things with the InvokeMethod.MethodParameter setting, but so far, haven't found anythign that works. I suspect it is some that requires a different wiring for this version of CSLA and the Rolodex sample is out of date.

Thanks,
Will

RockfordLhotka replied on Friday, June 18, 2010

The behavior of InvokeMethod changed in 3.8 so it invokes methods with zero or two parameters. The two parameter overload is:

public void YourMethod(object sender, ExecuteEventArgs e)

The ExecuteEventArgs parameter contains everything you got before, plus more information. This is also consistent with the Execute trigger action and the TriggerAction component.

I consider both InvokeMethod and Execute to be effectively obsolete. In fact I removed Execute entirely, since Blend now includes something just like it. I kept InvokeMethod from 3.8 into 4 for backward compatibility, but you should really consider switching to TriggerAction since it is far more flexible.

wjcomeaux replied on Monday, June 21, 2010

Yeah, last week while you were away I was talking back and forth with Blake over at Codesmith and we noticed that even CslaDataPortal is going away?

Can you point me to any examples showing the current method of using Csla with Silverlight. I saw somewhere that you were talking about a new video specificaly on Databinding with Silverlight. Any notes or samples on hand that demonstrate this new paradigm?

Thanks Rocky!
Will

RockfordLhotka replied on Monday, June 21, 2010

The data portal is certainly not going away. I think you mean CslaDataProvider.

CslaDataProvider is not going away either, but I view it as deprecated. The reason isn't because of the concept, but rather because the whole data provider idea seems to have fallen out of favor with Microsoft. Their VS10 tooling doesn't use it, nor does Blend 4.

The MVVM video series I'm working on covers the model that I'm focusing on with CSLA 4, and that video series should start to roll out over the next couple weeks.

wjcomeaux replied on Tuesday, June 22, 2010

Sorry, yes, DataProvider, nor Portal. :)

Thanks for the update. I watched the first video yesterday and I'm really looking forward to the next ones.

Will

Copyright (c) Marimer LLC