0

Hello everyone

I get some problems to use to navigation api of Prism 6 when i want to go in a child region (a region in an another region) by using the requestNavigate.

I have a view model ProgramsVM displayed in a region named ProgramContent. This VM have a command to switch to another VM named EditProgramViewModel in the same region.

But when i trigger the command, the requestNavigate fails miserably.

In fact, if i put a breakpoint in the method and inspect the regions founded in the region manager i do not find the region ProgramContent in the list despite the fact i am currently debugging an instance located in this region.

I have made a project to reproduce to problem : Sample Project if any is interested. To reproduce the problem, go to the second tad item and click the button 'Aller vers Edit'

Thanks in advance to any charitable souls.

  • Mins -

Ps: I'm using viewModelFirst and i find few tutorials about it. Does anybody have some links to share ?

Minskaya
  • 1
  • 1
  • I give up ! it'seems there is no way to use prism with view model first in a real LOB application.... – Minskaya Oct 08 '17 at 17:52
  • I've just found a hint in the documentation of prism related to my problem: "(for example, you are using WPF automatic data templates and adding your view model directly in the region), consider creating a custom RegionBehavior to forward the RegionContext to your view objects." but i'm not sure of what i have to do in my custom regionbehavior – Minskaya Oct 08 '17 at 18:59
  • Thanks Richards for your advice. When you say 'isn't really considered the most ideal MVVM approach' you want to say in the case of using prism or more generally ? – Minskaya Oct 08 '17 at 19:02
  • Strange : that precisely to reason why i try to use view model first: i don't want the viewmodel to know anything of the view event when navigating : region. i wanted to replace this.regionManager.RequestNavigate( RegionNames.ProgramContent, typeof(EditProgramView).Name) by this.regionManager.RequestNavigate( RegionNames.ProgramContent, typeof(EditProgramViewModel).Name) for this exact reason, which rules me to try view model first – Minskaya Oct 08 '17 at 19:43
  • May i missed something ? how navigate to view without knowing anything of the view ? – Minskaya Oct 08 '17 at 19:44
  • I've already read all the samples without find a suitable answer : - the path of the navigation is either a string put in the xaml, which i can't use because my command already often have a parameter or the target is computed by the vm - the path is a magic string representing the name of the view, which is imho a bad practice. Can you recommend me a sample representative of the good way ? – Minskaya Oct 08 '17 at 20:46
  • Example of things i try to avoid : sample 24 navigation journal _regionManager.RequestNavigate("ContentRegion", "PersonDetail", parameters); – Minskaya Oct 08 '17 at 20:50
  • Of course you can put the string in a const somewhere in a class ViewNames. That's what i've made but I've stopped because each time i add a view i have to edit this class it will become huge if the view name change the const is not updated That's even more complicated to handle when using modules – Minskaya Oct 08 '17 at 20:54
  • Your problem is you aren't using Prism navigation correctly. Prism doesn't care if you use VM first or View first. It doesn't care. It works the same. First off, you aren't registering your types for navigation. If you want to navigate, you must register them from navigation first. Please read the docs on navigation. Yo are using RegisterVIewIthRegion which does not register anything for navigation. It immediately injects the view into the region. Prism is plenty capable of doing anything in a "real LOB" app. You just have to know how to use it. –  Oct 08 '17 at 21:33
  • You should watch this course: https://www.pluralsight.com/courses/prism-introduction –  Oct 08 '17 at 21:33
  • Study these samples: https://github.com/PrismLibrary/Prism-Samples-Wpf. It doesn't matter what the navigation key is as that is irrelevant. Focus on the functionality and the concepts then apply to your approach. –  Oct 08 '17 at 21:34
  • I already tried to register with navigation with registerTypeForNvigation. Sorry my sample was not up to date, i made a lot of trials before postinf on SO. I think my problem results by the use of implicit datatemplate with regionname in it. i think i've read a discussion between you and another developer on this case and you suggested to not to use implicit datatemplate but you did not explain how to do. Could you give me a recommendation in this way ? – Minskaya Oct 08 '17 at 22:00
  • Oh... no.... you can't use a region inside a data template. That is not supported. I personally would never recommend using data templates for way too many reasons to list here. If you must do this, then use the work-around in this post http://southworks.com/blog/2014/05/20/updating-the-workaround-to-use-regions-in-datatemplates-to-prism-5/ –  Oct 08 '17 at 22:10
  • I 've found the discussion : [https://github.com/PrismLibrary/Prism/issues/694] where you said 'Only if you are relying on implicit templates to represent your View which I would never recommend'. I think it's my problem but i don't know another way to display a viewmodel in xaml – Minskaya Oct 08 '17 at 22:14
  • VM first is slow and problematic. You can still do view first and use your ViewModel names as a key when you register your view. You're creating a number of problems by trying to have a strongly typed navigation key. Simplify, don't complicate. Keep it simple. Just RegiterTyoeFOrNavigation(nameof(ViewMOdel)); Problem solved –  Oct 08 '17 at 22:17
  • Thanks again for having time to help me. – Minskaya Oct 08 '17 at 22:25

0 Answers0