Arguments for view creation

Topics: Prism v4 - WPF 4
Feb 10, 2012 at 10:31 PM



Is there a way to send arguments to a view while creating it ?


I have a scenario where the cmd1 and cmd2 ... create the same view with diff params which than doesn't change for its lifetime

I hope it is supported ?



Feb 11, 2012 at 4:32 PM

If you need to send manual parameters then is there any reason why defining them within your View's constructor does not meet your needs?

Are you using Dependency Injection within your View's Constructor?




Feb 27, 2012 at 9:46 PM

I use serviceLocator.GetInstance<T>() to create an instance, cannot pass arguments that way

I would prefer to create instances via prism/MEF but cant figure out a way



Feb 27, 2012 at 10:06 PM

Have you considered using RegionManager.RequestNavigate? This enables you to load a view into a region and pass in parameters in a uriquery. The View/ViewModel being navigated to then implements INavigationAware and in the NavigatedTo (or IsNavigationTarget or NavigatedFrom) method you can extract the uri parameters from the NavigationContext object. I use this technique and it works well.

There is more info on this technique in the Navigation chapter in the MSDN Prism documention. Take a look here and look for the section titled Passing Parameters During Navigation.

Hope this helps.

Feb 29, 2012 at 11:05 PM

thanks, will look into it

there are no wpf quickstarts for either Navigation & the machines here are tightly locked & cannot install the SL developer rutime, will look for wpf tutorials