WPF Prism - What is the point of using Prism Regions?

michael picture michael · Nov 1, 2011 · Viewed 8.1k times · Source

I'm just wondering what the point of regions are. I guess I don't understand the problem they solve.

For example, I see a lot of people using regions for a navigation region, but then why not just have an ItemsControl bound to an ObservableCollection instead of having a region and load in different navigation elements into that region?


A real-world example of it's use/benefits over the alternatives would rock!

Answer

Rachel picture Rachel · Nov 1, 2011

Regions allow you to define a spot in your program that exists for a specific purpose. So for example, you might have a Menu Region, or a Footer Region. You can then separate out the Views/ViewModels for those specific regions into their own section of the program.

So instead of having an ApplicationViewModel containing properties for the MenuViewModel and FooterViewModel, and having the View bind each section to those properties, you would have separate ViewModels for Menu and Footer, and your ApplicationViewModel would only deal with the content. It's a better way to separate some logical boundries in your application.

Personally I think Regions are horribly overused and abused. I almost never use them unless I have something like a Header or a Footer that is unrelated to the rest of my Application code. They're also mostly used in View-First development, and I prefer ViewModel-First.