Wpf & Csla

Wpf & Csla

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


ajj3085 posted on Wednesday, October 29, 2008

Hi,

I'm creating Wpf user-controls, which I'll combine in my main program to build the application. 

I've been getting designer crashes and not being able to render the Wpf user controls in the designer sometimes.

I've tracked the problem to some of my code actually executing in the designer.  I found the IsInDesignerMode attached property, and notice that Csla handly wraps this for use via Csla.DataPortal.IsInDesignMode static property.

So... it's clear that you need to take addition measures when building Wpf application to avoid running some code while in design mode.

Any advice along these lines, best practices, etc?  Will this be discussed at all in the forthcoming book?

Thanks
Andy

ajj3085 replied on Wednesday, October 29, 2008

Also, I noticed this code:

    private Csla.Server.DataPortalResult CreateDesignTimeObject(Type objectType, object criteria, Csla.Server.DataPortalContext context)
    {
      var obj = Activator.CreateInstance(objectType, true);
      object returnValue = null;
      returnValue = MethodCaller.CallMethodIfImplemented(obj, "DesignTime_Create");
      return new Csla.Server.DataPortalResult(returnValue);
    }

Does this mean that our BO's should implement DesignTime_Create to provide better designer support?

sergeyb replied on Wednesday, October 29, 2008

Only if you are interested in seeing some sample data in Blend (or VS designer) for WPF and SL applications.  The default will return null.  The problem used to be that you would get errors in blend as objects were instantiated and trying to connect to application server.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Wednesday, October 29, 2008 1:27 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] Wpf & Csla

 

Also, I noticed this code:

    private Csla.Server.DataPortalResult CreateDesignTimeObject(Type objectType, object criteria, Csla.Server.DataPortalContext context)
    {
      var obj = Activator.CreateInstance(objectType, true);
      object returnValue = null;
      returnValue = MethodCaller.CallMethodIfImplemented(obj, "DesignTime_Create");
      return new Csla.Server.DataPortalResult(returnValue);
    }

Does this mean that our BO's should implement DesignTime_Create to provide better designer support?


ajj3085 replied on Wednesday, October 29, 2008

Sample data might be useful, since the Infragistics grid doesn't display anything it seems without it.

I've had errors because the CslaDataProvider was raising DataChanged, which had an error that I attempt to handle.  Of course, it doesn't work in design mode, and thus VS crashes...

ajj3085 replied on Wednesday, October 29, 2008

Hmm.. I'm not getting any sample data back, but I seem to not be crashing anymore due to some checks I've added.

sergeyb replied on Wednesday, October 29, 2008

You should get some sample data.  I verrifed this in Blend, and I was able to see the data given that I overrode design_create method.  There is actually a demo project (WpfDesignTimeSupportDemo) that I used for testing in WPF.  Maybe you can loot and see what the differences are between your implementation and sample implementation. 

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Wednesday, October 29, 2008 2:56 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Wpf & Csla

 

Hmm.. I'm not getting any sample data back, but I seem to not be crashing anymore due to some checks I've added.


ajj3085 replied on Wednesday, October 29, 2008

Ok, I'll check it out. I'm using VS, haven't tried Blend yet.

Is it Design_Create or DesignTime_Create?

ajj3085 replied on Wednesday, October 29, 2008

Does DesignTime_Create have to return this?  I have it as a void method.

Mine is a little more complex... I try to follow the same data access patterns I usaually would and have calls to DataPortal.ChildFetch.  Would that screw things up?

sergeyb replied on Wednesday, October 29, 2008

Yes, it does have to return design-time object.  It does not have to return “this”, you could use some kind of factory instead.  You can probably use design time flag to bypass some other run time functionality as well.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Wednesday, October 29, 2008 3:24 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: Wpf & Csla

 

Does DesignTime_Create have to return this?  I have it as a void method.

Mine is a little more complex... I try to follow the same data access patterns I usaually would and have calls to DataPortal.ChildFetch.  Would that screw things up?


ajj3085 replied on Wednesday, October 29, 2008

Hmm.. ok, I looked again and saw that I missed it was returning a value.

It threw me because it had already created an instance and was calling an instance method.  I'll fix my code.

ajj3085 replied on Wednesday, October 29, 2008

Hmm... still no joy.  Not a huge deal.  I'm more concerned if there are any well known gotacha's when coding for Wpf using Csla... like specifically what code might get run if you follow the pattern in the Wpf sample.

sergeyb replied on Wednesday, October 29, 2008

Weird that this does not work – unless VS designer works differently from Blend.  You can try to attach debugger to blend and see if your design time code gets hist.  This will at least narrow down problem areas.  If you have data providers with initial load enabled, data portal will try to call fetch, but it should design time proxy currently, thus bypassing normal portal operations.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Wednesday, October 29, 2008 4:10 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: RE: Wpf & Csla

 

Hmm... still no joy.  Not a huge deal.  I'm more concerned if there are any well known gotacha's when coding for Wpf using Csla... like specifically what code might get run if you follow the pattern in the Wpf sample.


ajj3085 replied on Wednesday, October 29, 2008

Ya, I tried attaching a debugger and seeing if the DesignTime_Create was called.  My assembly was loaded as the breakpoint turned solid, but it never got hit.

I do feel a bit better though; the sample in svn doesn't work for me either, nor do my project or the sample work in Blend 2 SP1.

I'm on Vista Business with UAC.. but I wouldn't think that should matter.

Copyright (c) Marimer LLC