From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books
ive been putting off upgrading from 3.7.1 due to the breaking change using InvokeMethod.Resource. i have attempted to use the .Target the same way but it also fails can i get an example on how to change csla:InvokeMethod.Resource="{StaticResource data}"?
InvokeMethod now uses the DataContext to determine its target. The method to be invoked must be implemented on the DataContext of the Button object in your example.
Look at the MVVMExample sample projects (for SL and WPF) to see examples of using InvokeMethod.
Rocky
hi peer,
this seems to work, i changed my code from this
<StackPanel><Button csla:InvokeMethod.TriggerEvent="Click" csla:InvokeMethod.MethodName="Cancel" csla:InvokeMethod.Resource="{StaticResource data}" /><StackPanel/>
to
<StackPanel DataContext="{Binding Source={StaticResource data}}"> <Button csla:InvokeMethod.TriggerEvent="Click" csla:InvokeMethod.MethodName="Cancel"/><StackPanel/>
or
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
<StackPanel DataContext="{Binding Source={StaticResource data}}"> <Button> <interaction:Interaction.Triggers> <interaction:EventTrigger EventName="Click"> <csla:Execute MethodName="Cancel" /> </interaction:EventTrigger> </interaction:Interaction.Triggers> </Button></StackPanel>
germie
Hi Germie
I experience the same problem with version 3.8.0 (beta) and have no solution yet :(
Here is an exaple of the code wich is NOT working...
<Button x:Name="Refresh" Height="24" VerticalAlignment="Top" Content="Refresh" HorizontalAlignment="Left"csla:InvokeMethod.Target ="{StaticResource CompanyListData}" <-- This datasource works, the dagrid is filled csla:InvokeMethod.TriggerEvent ="Click" <-- When the click event fires the methodcaller throws an error ...csla:InvokeMethod.MethodName="GetCompanyList"/> <-- Valid method which is already fired in dataprovider's init to populate a datagrid
Have you found a solution yet ?
Peer
thnx for your response. after looking at the code it appeared there were two possible answers and they both seemed to get the job done. i changed my code from this
<StackPanel DataContext="{Binding Source={StaticResource data}}"> <Button> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <csla:Execute MethodName="Cancel" /> </i:EventTrigger> </i:Interaction.Triggers> </Button></StackPanel>
both seem to work the same. the only difference i see is that the button is no longer shaded out when the object is not dirty. is there other code in xaml that will handle this? or do you have to code this in yourself?
@Germie: Thanks for your reply, I'v changed my code BUT it didn't work out for me ... @Rocky: Thanks for the hint, I've checked the MVVMExperiment and your Blog about the MVVM pattern and event Binding. Also a verry interesting article on MSDN: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx Spend a lot of time reading and my view on this pattern is getting more clear every time. But I'v still a long way to go :)
As I said, my testproject->button still isnt working , the methodcaller throws still an error...
My dataprovider looks like this and is working fine, the data populates a datagrid.<csla:CslaDataProvider x:Key="CompanyListData"ObjectType="TmnOsis.Eos.Business.CompanyList, Business"FactoryMethod="GetCompanyList" ManageObjectLifetime="True"IsInitialLoadEnabled="True" DataChangedHandler="{StaticResource DataErrorDialog}"></csla:CslaDataProvider>
The Button looks like this:<Grid DataContext="{Binding Source={StaticResource CompanyListData}}"><Button x:Name="Refresh" csla:InvokeMethod.TriggerEvent="Click"csla:InvokeMethod.MethodName="GetCompanyList"/></Grid>
The object CompanyList looks like this: namespace TmnOsis.Eos.Business{public partial class CompanyList{public static void GetCompanyList(EventHandler<DataPortalResult<CompanyList>> callback){var dp = new DataPortal<CompanyList>();dp.FetchCompleted += callback;dp.BeginFetch();}}}
I have no Idea why this doesn't work properly. Tomorow I'll proceed with this issue.
Thank !Peer
does your "public static void GetCompanyList" get called at all when you click your button? i would try and put your button inside a stack pannel and use the stack pannels DataContext. just to test. i havent tried the grids yet.
@Germie: I've tried the stackpanel but is has no effect, the error is the same. @ Rocky,It won't get it into my mind....
1: The dataprovider works fine, the factory method is fired when initiating the page2: The buttons datacontext is bound with this same dataprovider3: When I cick the button, the dataproviderobject itself is targeted which has no GetCompanyList method and causes an error. target -> Csla.Silverlight.CslaDataproviderMethodName->"GetcompanyList"
When I change the InvokeMtehod in "Refresh" (CslaDataProvider method) , no error is invoked BUT i don't know where to put my code to execute the GetcompanyList method of my BO
I asume the object in the dataprovider is targeted and the InvokeMethod on that object is invoked. On this way I can invoke all kind of factorymethods in the client side of the BO. This mindset is probably killing me. In the MVVMExperiment you are invoking directly the client's factorymethods without using the cslaDataprovider, the invokemethod is directly bound to static resource which is the object itself.
(2 hours later ...)
Ok, I think I got it... The Refresh() of the CslaDataprovider invokes the dataprovider to refresh itself and therefore executing the registered FactoryMethod.(GetCompanyList). I still don't understand why this layer is between the BO and the Buttoncommand but I'll guess it has something todo with the MVVM pattern... It makes it harder to call another factorymethod, probably I have to create another dataprovider to invoke another factorymethod.
Why does my datagrid doesn't update itself when I call the refresh method on the dataprovider ? Do I manualy have to refresh the grid ? and if so, where do i store the code to do this? A possible scenario would be: seach-find form with searchparameter entry a seach button and a resultgrid..
Thanks
Rocky, I purchased the Silverlight training videos and downloaded the lastest samples updated for 3.8.2. Everything works except the buttons don't gray out like in the video. I am using the demo unmodified (except to linking to the csla.dll's). Is there something else that needs to be done get the grary out/disable back working on the buttons?