【发布时间】:2014-10-07 16:53:47
【问题描述】:
我在WPF 应用程序中使用Caliburn.Micro 和Modern-UI。在modern-ui 框架(即UserControl)内的“页面”上,我试图使用Conductor 来切换当前视图。这是我到目前为止所得到的:
注意:为简洁起见,从源中删除了命名空间
现代 UI 窗口中“页面”的 XAML
<UserControl x:Class="ShellView">
<ContentControl x:Name="ActiveItem" />
</UserControl>
ShellViewModel 的来源(指挥者)
[Export]
public class ShellViewModel : Conductor<IScreen>.Collection.OneActive
{
private readonly Test1ViewModel m_TestView1;
private readonly Test2ViewModel m_TestView2;
public ShellViewModel()
{
this.m_TestView1 = new Test1ViewModel();
this.m_TestView2 = new Test2ViewModel();
this.ActivateItem(this.m_TestView1);
}
}
Test1View 的 XAML 目前没有任何内容,只是普通的 UserControl 内容。
Test1ViewModel 的来源
public class Test1ViewModel : Screen
{
protected override void OnActivate()
{
//This DOES NOT show or fire, I even put a breakpoint to double check
Debug.Print("This should show in output");
}
}
当ActivateItem 被调用时,OnActivate 根本不会触发。我什至尝试在指挥中的视图模型Test1ViewModel 上调用ConductWith(this),但这没有用。我正在使用Modern-UI,这可能很重要,因为这同样适用于不使用Modern-UI 的不同项目。哦,当ActivateItem 被调用时,屏幕上会显示相应的视图(我添加了一些按钮来验证视图是否发生了变化)。
关于为什么在调用ActivateItem 后UserControl 会显示在ContentControl 中但OnActivate 根本不会触发的任何想法?
还有一件事......这可能也与它有关,但如果是这样,我不知道为什么或如何解决它。我正在使用这个类来使视图优先Modern-UI 与Caliburn.Micro 的模型优先方法一起工作。
internal class ModernContentLoader : DefaultContentLoader
{
protected override object LoadContent(Uri uri)
{
object content = base.LoadContent(uri);
if (content == null)
return null;
// Locate the right viewmodel for this view
object vm = ViewModelLocator.LocateForView(content);
if (vm == null)
return content;
// Bind it up with CM magic
if (content is DependencyObject)
ViewModelBinder.Bind(vm, content as DependencyObject, null);
return content;
}
}
【问题讨论】:
标签: wpf caliburn.micro modern-ui