Exporting Views

Jun 14, 2010 at 11:31 AM

Hi,

If I go the "PRISM" way and creates modules for the UI and so on, what is the best way to import this UserControl into the main Window?

Do I need to have some code-behind in the Main Window that Imports all UserControls and add this to the correct "Placeholder"?

Coordinator
Jun 14, 2010 at 2:30 PM
MEFedMVVM does not have a region manager like PRISM. You can use the PRISM Manager like in PRISM yet there are other ways as well how you can do this...

Not sure if there is any easy way how I can explain it unless I do a sample for it... It is on my list of sample to do yet I did not manage to find some time to do this sample yet.

Yet the idea is that a Module has a property that returns its UI representation and then the View bindins to that property of the Module...

as I said I will need to build a proper sample so that I can show how one can do such a thing

Regards
Marlon
WPF Blog - http://marlongrech.wordpress.com/
Microsoft MVP for Client App



On Mon, Jun 14, 2010 at 11:31 AM, pcedendahl <notifications@codeplex.com> wrote:

From: pcedendahl

Hi,

If I go the "PRISM" way and creates modules for the UI and so on, what is the best way to import this UserControl into the main Window?

Do I need to have some code-behind in the Main Window that Imports all UserControls and add this to the correct "Placeholder"?

Read the full discussion online.

To add a post to this discussion, reply to this email (MEFedMVVM@discussions.codeplex.com)

To start a new discussion for this project, email MEFedMVVM@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Jun 14, 2010 at 2:36 PM
Ok. That's great. I will try making it work.



Best regards,

Patrik Cedendahl,
System Developer
Sandvik IT Services AB
SE-811 81 Sandviken, SWEDEN

Office Phone: +46 26 262997
Mobile: +46 70 2728110
http://www.sandvik.com
patrik.cedendahl@sandvik.com

"marlongrech" <notifications@codeplex.com> wrote on 2010-06-14 15:30:12:

> "marlongrech"
>
> From:
>
> "marlongrech" <notifications@codeplex.com>
>
> To:
>
> patrik.cedendahl@sandvik.com
>
> Cc:
>
> Date:
>
> 2010-06-14 15:30
>
> Subject:
>
> Re: Exporting Views [MEFedMVVM:215926]
>
> From: marlongrech
> MEFedMVVM does not have a region manager like PRISM. You can use the
> PRISM Manager like in PRISM yet there are other ways as well how you
> can do this...
>
> Not sure if there is any easy way how I can explain it unless I do a
> sample for it... It is on my list of sample to do yet I did not
> manage to find some time to do this sample yet.
>
> Yet the idea is that a Module has a property that returns its UI
> representation and then the View bindins to that property of the Module...
>
> as I said I will need to build a proper sample so that I can show
> how one can do such a thing
>
> Regards
> Marlon
> WPF Blog - http://marlongrech.wordpress.com/
> Microsoft MVP for Client App
>
>

> On Mon, Jun 14, 2010 at 11:31 AM, pcedendahl <notifications@codeplex.com
> > wrote:
> From: pcedendahl
> Hi,
> If I go the "PRISM" way and creates modules for the UI and so on,
> what is the best way to import this UserControl into the main Window?
> Do I need to have some code-behind in the Main Window that Imports
> all UserControls and add this to the correct "Placeholder"?
> Read the full discussion online.
> To add a post to this discussion, reply to this email (
> MEFedMVVM@discussions.codeplex.com)
> To start a new discussion for this project, email
> MEFedMVVM@discussions.codeplex.com
> You are receiving this email because you subscribed to this
> discussion on CodePlex. You can unsubscribe or change your settings
> on codePlex.com.
> Please note: Images and attachments will be removed from emails. Any
> posts to this discussion will also be available online at codeplex.com
>
> Read the full discussion online.
> To add a post to this discussion, reply to this email (
> MEFedMVVM@discussions.codeplex.com)
> To start a new discussion for this project, email
> MEFedMVVM@discussions.codeplex.com
> You are receiving this email because you subscribed to this
> discussion on CodePlex. You can unsubscribe or change your settings
> on codePlex.com.
> Please note: Images and attachments will be removed from emails. Any
> posts to this discussion will also be available online at codeplex.com

This e-mail is confidential and it is intended only for the addressees. Any review, dissemination, distribution, or copying of this message by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error, kindly notify us immediately by telephone or e-mail and delete the message from your system. The sender does not accept liability for any errors or omissions in the contents of this message which may arise as a result of the e-mail transmission.

Feb 2, 2011 at 1:43 PM
marlongrech wrote:
MEFedMVVM does not have a region manager like PRISM. You can use the PRISM Manager like in PRISM yet there are other ways as well how you can do this...

Hi,

I'm trying to create a PRISM/MEFedMVVM app and there is a problem with Importing PRISM services into the ViewModels. To reproduce the problem, modify EmailViewModel constructor (in MEFedMVVMAndPrism example solution) with the constructor below, then break to see that the imported IRegionManager has no regions at all. This is different from e.g. EmailContactModule imports (instantiated by PRISM), where one can see the application regions.

 

		[ImportingConstructor]
		public EmailViewModel(IMediator mediator, IEmailService emailService, IVisualStateManager stateManager, IRegionManager regionManager)

Do you have a workaround for this problem?

- Jussi

 

here to see that regionManager has no regions at
Feb 2, 2011 at 2:35 PM

Hi again,

After some more testing I've found that ViewModels importing IEventAggregator also get a separate instance from the rest of the application. Trying to import a IModuleManager inside a view model generates an exception. It seems that MEFedMVVM needs some changes before it can be used together with Prism.

Coordinator
Feb 3, 2011 at 7:55 AM

trying following the steps in this post and if you do not manage let me know

 

http://marlongrech.wordpress.com/2011/01/03/mefedmvvm-with-prism-4/

Feb 3, 2011 at 8:12 AM
Edited Feb 3, 2011 at 8:27 AM

I did follow it and ran into problems. Two posts above there is a way to reproduce the problem with the example you included in that post.

Edit: To me it seems that MEFedMVVM and Prism instantiate separate instance of exported classes, like there were two containers or exporters.

Another easy way to reproduce the problem with your example is to modify ContactsListViewModel constructor to look like this:

[ImportingConstructor]
public ContactsListViewModel(IContainerStatus containerStatus, ILoggerFacade logger,
            IDataAccess dataAccess, IMediator mediator, IModuleManager moduleManager)
		{
The addition of IModuleManager to the import list causes ViewModel instantiation from within MEFedMVVM to fail. Importing IModuleManager elsewhere (where Prism is responsible for exporting the instance) works.

Coordinator
Feb 3, 2011 at 8:28 AM

mmmm...... where are you using the IRegionManager beside from ViewModels?

Feb 3, 2011 at 8:38 AM
Edited Feb 3, 2011 at 8:44 AM

In the IModule initialization method, for example. There you can see two regions. But in the view model you can't. Same thing with IEventAggregator and IModuleManager. There are separate instances depending on where the import is.

In your example solution, put a break point somewhere in here to verify that it is different from the one that gets imported in the ViewModel:

[ModuleExport(typeof(EmailContactModule))]
public class EmailContactModule : IModule
{
readonly IRegionManager _regionManager;

[ImportingConstructor]
public EmailContactModule(IRegionManager regionManager)
{
_regionManager = regionManager;
}

#region Implementation of IModule

public void Initialize()
{
var view = new EmailView();

// Add it to the region
IRegion region = _regionManager.Regions[Regions.SideModule];
region.Add(view, "Email");
}

#endregion
}
Coordinator
Feb 4, 2011 at 9:16 AM

mmm... this is def something i need to look into... till now I never needed to use the IRegionManager in ViewModels thus I did not have this issue... Also instead of EventAggregator I use the IMEdiator which comes with MEFedMVVM. 

I can see why there is this issue... I will try and solve it in the next version.... Thanks for reporting this... much appreciated!

Feb 4, 2011 at 11:15 AM

Thanks for looking into this! Meanwhile, I will provide the necessary Prism imports to my viewmodels some other way until the issue is solved.

I have to say that I think really highly of MEFedMVVM, it is perfect for us for providing design time data and for linking views with viewmodels. It has made our application design simpler and has worked perfectly so far. So instead of you thanking me, I really should thanking you! ;-)

Feb 15, 2011 at 8:54 AM

Have you had any time to look into this issue? With our project growing bigger, this is starting to create more and more problems. Especially having an incorrect instance of region manager created for view models and services is proving extremely inconvenient and requires workarounds that are not pretty. To support Prism navigation properly, we need the correct RegionManager everywhere.

Coordinator
Feb 16, 2011 at 7:24 PM

there is a workaround....

 

do this in the CreateShell method of the bootstrapper (the line in bold does the trick)

protected override DependencyObject CreateShell()

 {

//init MEFedMVVM composed
        MEFedMVVM.ViewModelLocator.LocatorBootstrapper.ApplyComposer(this);

ViewModelRepository.Instance.Resolver.Container.ComposeExportedValue<IRegionManager>( Container.GetExportedValue<IRegionManager>());

return this.Container.GetExportedValue<Shell>();

}

Feb 17, 2011 at 10:55 AM

That's excellent, thank you for the workaround!

Coordinator
Feb 22, 2011 at 4:05 PM

I just uploaded a better fix for working with PRISM to share the same composition container... have a look at the latest check in

 

description of the patch here ... http://mefedmvvm.codeplex.com/workitem/15391

Feb 23, 2011 at 4:49 PM

Thanks, the patch is working fine for us!