csla:InvokeMethod.Resource="{StaticResource data}"

csla:InvokeMethod.Resource="{StaticResource data}"

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


germie posted on Monday, February 01, 2010

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}"?

Peer replied on Monday, February 08, 2010

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

RockfordLhotka replied on Monday, February 08, 2010

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.

germie replied on Monday, February 08, 2010

thnx for your response. Big Smile 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>
<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>
      <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?

Peer replied on Wednesday, February 10, 2010

@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 page
2: The buttons datacontext is bound  with this same dataprovider
3: When I cick the button, the dataproviderobject itself is targeted  which has no GetCompanyList method and causes an error.
target -> Csla.Silverlight.CslaDataprovider
MethodName->"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... Smile 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

Peer

 

 

 

 

jeffq replied on Sunday, February 21, 2010

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?

trives replied on Monday, April 05, 2010

Hi Jeffq,

I assume that you figured out your problem since your post is pretty old.  I have the same problem.  I changed the demo code to look like this (added IsEnabled on the buttons):

 <StackPanel Orientation="Horizontal" DataContext="{Binding Source=StaticResource data}}">
<Button Content="Save"
Margin="5"
IsEnabled="{Binding CanSave}"
csla:InvokeMethod.TriggerEvent="Click"
csla:InvokeMethod.MethodName="Save" />
<Button Content="Cancel"
Margin="5"
IsEnabled="{Binding CanCancel}"
csla:InvokeMethod.TriggerEvent="Click"
csla:InvokeMethod.MethodName="Cancel" />
</StackPanel>

Is there some other way?

RockfordLhotka replied on Monday, April 05, 2010

Binding IsEnabled as you are doing is the best approach.

Older versions of PropertyStatus were designed to alter the UI control's appearance directly. That seemed like a good idea, but really doesn't fit the XAML worldview.

So while that code is still there, I consider it obsolete and will eventually remove it. Instead, I strongly recommend that people bind IsEnabled, Visibility and other UI control properties to the properties of PropertyStatus and/or your viewmodel to control the UI. That is much more flexible and fits into the XAML worldview.

germie replied on Monday, February 08, 2010

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

Peer replied on Tuesday, February 09, 2010

@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

germie replied on Tuesday, February 09, 2010

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.

Copyright (c) Marimer LLC