Layout Management

Topics: Prism v1, Prism v2 - WPF 3.5
Apr 6, 2009 at 10:56 AM
Has anyone attempted to resolve the dependency on region string names to seat views?  I created a config-driven LayoutManager which allowed you to define a layout control (with its own regions) and specify views and their target regions.  This removed the need for region name constants in my infrastructure assembly and allowed me to dynamically load any number of pre-defined layouts.  Programmatic manipulation of regions and views would still need to resort to string names.  This worked well in Prism v1, but not v2.  Prism v2 has made me reconsider this approach.

I never felt comfortable injecting views into named regions from within the module, and have always sought to do this outside the module using a specialised layout module (or the LayoutManager).  The StockTraderRI project seems to have the views driving the UI.  Maybe I'm missing the underlying concept, but this somehow feels wrong.  It seems the responsibility should not lie with the view or with the region, for that matter; but with another layer whose responsibility is to pull all the components together and assemble the resultant application.  I'm not sure what pattern this would be, but it is something on the order of UI Orchestration.

With regards to code reuse, has anyone successfully taken bits of the StockTrader and dropped them into another Prism application?

I'm quite interested in working out a solution for this if anyone is interested in collaborating.  I'm still reviewing the changes in v2, which may shed some light on this.


Apr 6, 2009 at 4:16 PM
Edited Apr 6, 2009 at 4:16 PM
hi rgramann,

Creating a seperate layoutmanager is a scenario which you can use if you need a LOT of flexibilty. We felt that most applications typically didn't need that level of flexibility and requiring it for each prism app would increase the complexity.

However, if you find that you do need that kind of flexibilty, you are correct, it's a great way to solve that.

If your app's layout is static at runtime (and only dynamic at config time), i've found the view discovery approach to be very useful in creating a seperate layout manager. 

Hope this helps,
Erwin 
Apr 6, 2009 at 10:00 PM
Hi Erwin,

Thanks for the response.  Unfortunately, my current project does require a lot of flexibility.  I'll continue with the LayoutManager approach, as this is a workable solution.  I suspect view injection via the LayoutManager is probably the way to go.

Thanks for your help.

Cheers,

Ron
 
Apr 7, 2009 at 7:44 PM
Hi Ron,

I believe that I'm trying to achieve a similar view construction, storage and discovery mechanism similar to the functions you've mentioned.  As you mentioned, this gives the application and the user more flexibility. 

I'm interested in possibly collaborating with you.  Let's start a conversation and see if we're trying to achieve the same goals.

Cheers,
Jeff
Apr 8, 2009 at 7:43 AM
Hi Jeff,

Send me an email - ron at gramann dot co dot uk

rg
Apr 11, 2009 at 7:56 PM
Hi All,

I have recently completed work on a LayoutManager for Prism v2.  The LayoutManager allows you to define layout controls, views and their target regions in your app.config.  Layouts can exist as loose Xaml or within an assembly.  Supports both Views and ViewModels.  If anyone is interested I can send you the zipped solution (VS 2008 SP1).  Would like some peer review and feedback, and once stabilized I'll post on CodeProject.

  <layoutManager shellName="Shell" >
  <layouts>
    <layout name="FirstLayout" filename="Layout\FirstLayout.xaml" >
      <views>
        <view typeName="LayoutManager.Infrastructure.IViewA, LayoutManager.Infrastructure" regionName="TopLeft" visibility="Visible" />
        <view typeName="LayoutManager.Infrastructure.IViewB, LayoutManager.Infrastructure" regionName="BottomLeft" visibility="Visible"/>
        <viewModel typeName="LayoutManager.Infrastructure.IViewModelC, LayoutManager.Infrastructure" regionName="Right" visibility="Visible" viewProperty="View"/>
        <viewModel typeName="LayoutManager.Infrastructure.IMenuViewModel, LayoutManager.Infrastructure" regionName="Menu" visibility="Visible" viewProperty="View"/>
      </views>
    </layout>
    <layout name="SecondLayout" filename="Layout\SecondLayout.xaml" >
      <views>
        ...
      </views>
    </layout>
    <layout name="ThirdLayout" typeName="LayoutManager.Infrastructure.IThirdLayout, LayoutManager.Infrastructure" isDefault="true">
      <views>
        ...
      </views>
    </layout>
  </layouts>
  </layoutManager>

Just send an email to:  ron at gramann dot co dot uk


Apr 13, 2009 at 3:31 PM
Just posted an article on CodeProject - Layout Manager for Prism v2 - http://www.codeproject.com/KB/WPF/PrismLayoutManager.aspx

Any feedback or comments (or votes) are welcome.

Cheers

Ron
Apr 28, 2009 at 9:50 PM

For those interested...I posted an update to the LayoutManager on CodeProject.

http://www.codeproject.com/KB/WPF/PrismLayoutManager.aspx

Changes include: decoupled configuration from app.config, added ConfigLayoutProvider and XamlLayoutProvider.  LayoutManager, Layouts, Views and ViewModels are now DependencyObjects, allowing you do define your layout in Xaml.  Code clean-up and namespace change.

Ron