Caliburn.Micro HelloWindowManager Sample - View location not working

ぃ、小莉子 提交于 2019-12-12 06:58:58

问题


The HelloWindowManager Caliburn.Micro sample demonstrates displaying a Window (View) as Modal, Modeless or Popup and works just fine. However it has the views and Viewmodels in the project root so I wanted to tidy it up and have it use the default convention for view and view model locations, so I made the following changes:

  1. Created a Views folder and moved both the ShellView.xaml and DialogView.xaml within it
  2. Created a ViewModels folder and moved the matching View Models
  3. Adjusted the namespace in the 4 files to reflect the move

On running the revised sample now I have the weird behaviour that while the 'Open Modal' button works perfectly, thus demonstrating that the View for the VM CAN be found, both the Open Modeless and the Open Popup buttons result in the message "Cannot find View for caliburn.Micro.HelloWindowmanager.ViewModels.DialogViewModel"

Any ideas?

Edited to add:

Absent any answers from anyone, I modified the sample to use the SimpleContainer instead of MEF - and it displays exactly the same behaviour as above.

e.g. This call works:
var result = windowManager.ShowDialog(new DialogViewModel());

but these two calls result in the 'cannot find view...' error message

windowManager.ShowWindow(new DialogViewModel(), "Modeless");

windowManager.ShowPopup(new DialogViewModel(), "Popup", settings);

Should I somehow be adding DialogViewModel to the SimpleContainer?


回答1:


Pretty sure my comment is the answer...

within the views folder you will all so need a folder called Dialog within that folder you will place Modeless.xaml and Popup.xaml both with of which need to have for example ".Views.Dialog.Modeless" as their namespace respectively. Its a viewlocator drill that even I have fought with many times. :/

Note: This just semantics you could put in the Namespace directly without the folder but from an organizational structure of the project it helps to understand it better.



来源:https://stackoverflow.com/questions/25503806/caliburn-micro-hellowindowmanager-sample-view-location-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!