Are there any design patterns to compose views within a parent view during runtime? Say we are composing the views in a workflow tab and views in the tabcontrol depend on the country, store type and/or other conditions.

This is a MVP, WPF, PRISM application.

  • Hmm, why not use DataTemplateSelectors which select the DataTemplates based on the locale or other criteria?
    – Falcon
    Sep 7, 2011 at 17:09
  • 1
    Sounds like functional composition to me.
    – snakehiss
    Sep 8, 2011 at 4:33

2 Answers 2


The closest design pattern I can think of is decorator pattern. That said, are you nesting views, or enabling/disabling/auto-populating fields based on other selections in the UI, in which case you may want to use the strategy pattern?


Would a some form of Factory suffice?

I'm thinking something along the lines of

    var dynamicView = ViewFactory.CreateView(countryCode, storeType, otherConditions);


    var countryView = CountryViewFactory.Create(countryCode);
    var storeTypeView = StoreTypeViewFactory.Create(storeType);
    var otherView = OtherViewFactory.Create(otherConditions);
    RenderPartial("CountrySection", countryView);
    RenderPartial("StoreTypeSection", storeTypeView);
    RenderPartial("OtherSection", otherView);
  • Chris, we are using Unity for DI else factory would be one my choices too. but i was actually wondering whats the best design pattern that can be followed for this scenario!
    – ioWint
    Sep 16, 2011 at 3:56
  • The only other thing I can think off is the Composite pattern (en.wikipedia.org/wiki/Composite_pattern) but they may not be appropriate depending on the structure of the views you have.
    – Chris Lee
    Sep 16, 2011 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.