Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Hmm, why not use DataTemplateSelectors which select the DataTemplates based on the locale or other criteria? – Falcon Sep 7 '11 at 17:09
Sounds like functional composition to me. – dietbuddha Sep 8 '11 at 4:33

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?

share|improve this answer

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);
share|improve this answer
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 '11 at 3:56
The only other thing I can think off is the Composite pattern ( but they may not be appropriate depending on the structure of the views you have. – Chris Lee Sep 16 '11 at 18:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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