简体   繁体   English

Caliburn.Micro视图切换

[英]Caliburn.Micro view switching

In a CM WPF application I have following items: 在CM WPF应用程序中,我具有以下各项:

<Window> <!-- Shell Window -->
 <ContentControl x:Name="MainRegion">
 <ContentControl x:Name="SearchRegion">
<Window>

Views: 浏览次数:

MainRegionView
SearchRegionView

View Models: 查看模型:

MainRegionViewModel //implements Conductor<Screen>
SearchRegionViewModel //implements Conductor<Screen>

I neet to switch the view of SearchRegionViewModel from MainRegionViewModel. 我没有从MainRegionViewModel切换SearchRegionViewModel的视图。 Following code is executed inside MainRegionViewModel . 以下代码在MainRegionViewModel内部执行。

ViewModelTest test = new ViewModelTest();
//Calling the method from object reference
searchRegionViewModel.ActivateItem(test);

Problem: the view is not loaded in SearchRegionView. 问题:该视图未加载到SearchRegionView中。 How can i load the view to SearchRegion? 如何将视图加载到SearchRegion?

Your MainRegionViewModel & SearchRegionView need to implement Screen and your ShellViewModel is the one that need to implement the Conductor. 您的MainRegionViewModelSearchRegionView需要实现Screen,而ShellViewModel是需要实现Conductor的那个。 After that, you need to bind the ActiveItem in the XAML (ShellView.xaml). 之后,您需要在XAML(ShellView.xaml)中绑定ActiveItem。

<ContentControl x:Name="ActiveItem"></ContentControl>

Inside your ShellViewModel use Activate(YourViewModel) . 在ShellViewModel内部,使用Activate(YourViewModel)

Here is an Example 这是一个例子

If you want to change the ActiveItem inside your MainRegionViewModel, You need to look at the EventAggregator to publish a message to your ShellViewModel to Activate the desire ViewModel 如果要更改MainRegionViewModel内部的ActiveItem,则需要查看EventAggregator以将消息发布到ShellViewModel以Activate所需的ViewModel。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM