Access factory method throught click event

Access factory method throught click event

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


ax4413 posted on Tuesday, September 22, 2009

What is the syntax needed to call the factory method in c# code behind.

I can access the factory methods using the data provider factoryMethod property. However I need to be able to call this through a button click event. What is the syntax to do this please?

RockfordLhotka replied on Tuesday, September 22, 2009

So you are in WPF or Silverlight, and you want to invoke a method on an abitrary object (either the data provider or your business object) in response to a Click event?

Handle the event in code-behind, get the data provider from the Resources dictionary and invoke its Refresh() method. Several of the WPF/Silverlight sample apps get the data provider from Resources and interact with it in code-behind - just check through the sample apps.

Or search the web for the MVVM pattern. Even if you don't buy into the MVVM pattern itself, the first thing every MVVM framework/toolkit solves is the problem of invoking arbitrary methods in response to UI events (such as Click).

CSLA .NET for Silverlight has the InvokeMethod component that does this. In 3.6/3.7 there are limitations on what it can do.

In 3.8 the limitations are mostly removed, so InvokeMethod can handle any event (as far as I can tell) and can invoke methods on arbitrary objects (as long as they are bindable from XAML).

Also in 3.8 there's a new trigger action named Execute. The Execute action does much of what InvokeMethod does, but within the Blend 3 trigger framework model (which imposes certain limits).

Fele replied on Thursday, January 21, 2010

Can somebody provide code example of calling MobileFactory object from (MVVM) model class?

RockfordLhotka replied on Thursday, January 21, 2010

var dp = new DataPortal<Customer>();
dp.FetchCompleted += (o, e) =>

{

  // process results (e.Error/e.Object) here

};

dp.BeginFetch();

 

Copyright (c) Marimer LLC