Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 410
michael Avatar asked Nov 01 '11 17:11

michael


People also ask

What is region in Prism?

Prism regions are essentially named placeholders within which views can be displayed. Any control in the application's UI can be a declared a region by simply adding a RegionName attached property to it, as shown here.

Why do we need prism in WPF?

Prism helps to create flexible applications by allowing them to be more easily updated as new capabilities are developed and integrated. Prism also allows WPF applications to be developed using common services and components, allowing the application to be deployed and consumed in the most appropriate way.

What is Prism for WPF?

Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in WPF, and Xamarin Forms. Separate releases are available for each platform and those will be developed on independent timelines.

What is Shell in Prism?

The shell is usually the MainWindow or MainPage. Implement this method by returning an instance of your application's shell class. In a Prism application, you can create the shell object, or resolve it from the container, depending on your application's requirements.


1 Answers

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.

like image 181
Rachel Avatar answered Sep 22 '22 20:09

Rachel