我在我的MVVM WPF应用程序中使用Caliburn.Micro 3。通过遵循documentation和提供的示例,我成功地实现了在我的应用中导航。如何使用Caliburn.Micro制作导航服务?
但是,我想要关注SOLID principles,我认为使用ShellViewModel作为Conductor是违反单一责任原则。
为了解决这个问题,我创建了一个控制我的导航的“服务”,但是我无法设置显示ActiveItem的。当我浏览时,我将ViewModel名称视为字符串,而不是与其关联的视图。
public class NavigationService : Conductor<IScreen>, INavigationService
{
public void GoTo<T>() where T : IScreen
{
var viewModel = IoC.Get<T>();
ActivateItem(viewModel);
}
}
而我从我的“ShellViewModel”中使用它。
public class ShellViewModel : PropertyChangedBase
{
private readonly INavigationService _navigationService;
public HomeViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
}
public INavigationService NavigationService => _navigationService;
public void ShowChartPage() => _navigationService.GoTo<TimeSeriesViewModel>();
}
的ContentControl中从我ShellView:
<ContentControl Content="{Binding NavigationService.ActiveItem}" />
我缺少的东西?
感谢您的帮助,我需要使用cal:View.Model附加属性。 – Romain