Prism icon indicating copy to clipboard operation
Prism copied to clipboard

[WPF] Prism regions in templated controls do not work

Open dvorn opened this issue 10 years ago • 10 comments

Package info

  • Platform: WPF
  • Prism version: 2, 4, 5, 6

Actually this is an old well-known issue: Region Registration Fails w/ Templated Controls

The codeplex workitem above provides also a solution - a modification of RegionManagerRegistrationBehavior to account for templated controls.

While this can be achieved without modification of the Prism library by creating and registering a custom modified RegionManagerRegistrationBehavior, I suggest to include the fix into the library.

I do not expect that anybody's code may be broken by the fix.

dvorn avatar Jul 31 '16 13:07 dvorn

I do not expect that anybody's code may be broken by the fix.

Obviously we can't rely on this :)

This is a scenario I'm not we want to support out of the box. There should be very few scenarios when you would do this, and I have never had to do this personally. I'll have to think about this. This may just be a "how to" in the documentation.

brianlagunas avatar Aug 05 '16 04:08 brianlagunas

This is needed if you do View Model-first.

dvorn avatar Aug 05 '16 04:08 dvorn

Only if you are relying on implicit templates to represent your View which I would never recommend. That's slow as hell and introduces a number of other development pains.

brianlagunas avatar Aug 05 '16 05:08 brianlagunas

Only if you are relying on implicit templates to represent your View which I would never recommend.

But the documentation says Navigation Using the Prism Library for WPF

Note: The preceding description illustrates view-first navigation, where the URI refers to the name of the view type, as it is exported or registered with the container. With view-first navigation, the dependent view model is created as a dependency of the view. An alternative approach is to use view model–first navigation, where the navigation URI refers to the name of the view model type, as it is exported or registered with the container. View model–first navigation is useful when the view is defined as a data template, or when you want your navigation scheme to be defined independently of the views.

.

That's slow as hell

Premature optimization, eeh?

introduces a number of other development pains.

It allows to run complete user scenarios with real view models in acceptance tests.

And the whole point of this ticket is to remove one of the pain points.

dvorn avatar Aug 05 '16 06:08 dvorn

Yeah.. the doc snippet you pasted doesn't point out anything ground breaking. Using implicite data templates for your apps primary views is extremely slow in WPF. I would never do this in any WPF app I build. That's just my opinion.

It allows to run complete user scenarios with real view models in acceptance tests

You can do this with view first or VM first. The view approach should have no impact on testing your VMs.

brianlagunas avatar Aug 05 '16 06:08 brianlagunas

To summarize:

a) this change does not affect existing code and view-first scenarios.

b) But it allows creation of regions in data templates which is useful in view model-first scenarios.

What are the objections to that?

dvorn avatar Aug 05 '16 07:08 dvorn

this change does not affect existing code and view-first scenarios.

We need to verify this and cannot assume. There are many scenarios around regions and scoped regions (View and VM first). We also need to determine the performance impact we are introducing my complicating the logic. This may seem like a simple change, but we must do a proper review before making this change as it touches a stable and very important aspect of the Prism code base. This is a high risk change that I am not in a hurry to make.

brianlagunas avatar Aug 05 '16 07:08 brianlagunas

There are also a number of ways to solve this. This is also another good approach http://southworks.com/blog/2011/11/10/regions-inside-datatemplates-in-prism-v4-using-a-region-behavior/

brianlagunas avatar Aug 05 '16 08:08 brianlagunas

This is not supported out of the box.

brianlagunas avatar Nov 13 '16 03:11 brianlagunas

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 30 '20 20:01 lock[bot]