Print Page | Close Window

Caliburn Micro and multiple view-models with the same view caused a problem

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3850
Printed Date: 28-Apr-2024 at 2:14am


Topic: Caliburn Micro and multiple view-models with the same view caused a problem
Posted By: cefernan
Subject: Caliburn Micro and multiple view-models with the same view caused a problem
Date Posted: 10-Dec-2012 at 11:26am
Hello,

I have implemented a different behavior as described in:
http://www.emidee.net/index.php/2010/09/30/caliburn-micro-how-to-use-the-same-view-for-multiple-view-models/

So, after that, my application shows always the same message in any exception:
Cannot create Cocktail.DialogHostBase

I guess the problem is that my code (ViewLocatorConfigurator) is not able to find the correct view to show the message.

Do you have any suggestion to solve that?

PS: My application is based on TempHire architecture.



Replies:
Posted By: mgood
Date Posted: 10-Dec-2012 at 12:45pm
I don't have much to go on here. Cocktail.DialogHostBase is a ViewModel and not a View. It is created through MEF by the DialogManager whenever you try to show a popup and it should already be created by the time CM tries to find the corresponding View, which would invoke your custom locator logic. It sounds like your code is accidentily trying to create the ViewModel instead of the View. Maybe you can post the stack trace so I have a better idea where exactly this is happening.


Posted By: cefernan
Date Posted: 11-Dec-2012 at 11:50am
Actually, my code (or the code copied from that link) tries to find a View considering the view specified in UseView attribute or using the name of the ViewModel removing the word Model.

So, after your reply, I decided to check what was going on and had my problem solved removing that ViewLocatorConfigurator class and UseViewAttribute.

Now, I have a better solution (or the correct one). I added a rule in ViewLocator.NameTransformer with a regex that solved my problem (use the same view for multiple view-models) and I have no problems on Cocktail :) 

Thank you Marcel.



Posted By: mgood
Date Posted: 11-Dec-2012 at 11:57am
Great! Yes, the NameTransformer is the proper way to handle custom view resolution.



Print Page | Close Window