CSLA and Expression Blend problem

CSLA and Expression Blend problem

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


Moh_Abed posted on Tuesday, February 27, 2007

Hi all,

I'm currently porting my CSLA application to WPF, so I am considering separating the design of UI from UI development, so I intend to use MS Expression blend for designing the UI, what is the best technique to bing CSLA object to UI ?, should binding be implemented in xaml or code behind ?

the regular binding in xaml which is supported in the designer (Expression Blend) does not work simply because if expects a default public constructor which is not the case in CSLA, the other way is to use Object Data Provider:

<Window.Resources>

<ObjectDataProvider MethodName="GetBranchesList" x:Key="BranchCollection"

ObjectType="{x:Type ReadOnlyCollections:BranchesList}" />

</Window.Resources>

...

<Window.DataContext>

<Binding Mode="OneWay" Source="{StaticResource BranchCollection}"/>

</Window.DataContext>

...

<ListBox ItemsSource="{Binding Mode=OneWay}" IsSynchronizedWithCurrentItem="True" />

This code uses ObjectDataProvider as the binding source, MethodName defines the name of the static method used to fetsh the data from CSLA without writing a single line of code in code behind.

the problem that I faced is, when using Expression Blend, the designer refuse to show the design throwing exception because it try to call the method (GetBranchesList), does anybody face this problem ? i guess the cause of the problem is that the designer try to actually fetch the data to present it in the designer or so.

did anybody found a solution to this problem? what are the other ways of handling WPF binding in the context of CSLA

RockfordLhotka replied on Tuesday, February 27, 2007

Right now you can use XAML binding to bind the fields, but you must write one line of code to actually create the object and make it be the current data context.

In other words, you can't use the ObjectDataProvider, because it has many of the same limitations as the ObjectDataSource control in ASP.NET, and it simply won't work with objects that are created using a factory design pattern. Sad but true...

RockfordLhotka replied on Thursday, March 01, 2007

I have been spending a lot of time on WPF, and if you are willing to live on the bleeding edge, you can now try the new Csla.Wpf.CslaDataProvider control. Click here for details.

In my limited testing it seems to work quite nicely, allowing you to specify the object's type, factory method and factory parameters in XAML.

Right now the only way to get the code is to pull it directly from the svn repository.

svn://svn.lhotka.net/csla/trunk/cslacs

Also, right now some of these features are only in C#. Once I'm more confident that they're stable, I'll port them to VB.

Moh_Abed replied on Sunday, March 04, 2007

Thanx very much,

I am on my way testing it :)

Moh_Abed replied on Monday, March 05, 2007

Small bug, failed to execute factory method when there are more than overload of the factory method, say we have 2 factory method, GetBranches() and , GetBranches(filterText), the reflection code in DoQuery should consider Factory parameters to get the required factory method, i did this modification and it worked:

private void DoQuery(object state)

{

...

try

{

// get factory method info

MethodInfo factory = request.ObjectType.GetMethod(

request.FactoryMethod,

BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy,

null, GetFactoryParameterTypes(request.FactoryParameters), null);

...

}

...

private Type[] GetFactoryParameterTypes(List<object> list)

{

List<Type> typeList = new List<Type>();

foreach (object obj in list)

{

typeList.Add(obj.GetType());

}

return typeList.ToArray();

}

 

RockfordLhotka replied on Monday, March 05, 2007

Good point, I hadn't thought about overloads of the factory. I'm traveling today through Wednesday, but I'll work a fix into the code sometime this week.

Thanks!

Copyright (c) Marimer LLC