Caliburn.Micro HelloWindowManager Sample - View lo

2019-09-19 20:04发布

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条回答
闹够了就滚
2楼-- · 2019-09-19 20:45

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.

查看更多
登录 后发表回答