Xaml 如何组织ViewModel和View项目以使用View.Context切换?
我的视图和viewmodels位于不同的项目中,我使用ViewLocator.AddNamespaceMapping调用映射所有内容 如何继续保持事物的独立性并使用视图。建议进行上下文切换 假设我的viewmodel项目包含顶级功能文件夹: MyViewModels/ --/FormDesigner/FormDesignerServiceModel.cs --/GroupDesigner/GroupDesignerServiceModel.cs --/FilterDesigner/FilterDesignerViewModel.cs 等等 我的视图项目如下: 我的观点/ --/FormDesigner/FormDesignerView.xaml --/GroupDesigner/GroupDesignerView.xaml --/FilterDesigner/FilterDesignerView.xaml 我目前在我的引导程序中映射如下: ViewLocator.AddNamespaceMappingMyViewModels,MyViewsXaml 如何组织ViewModel和View项目以使用View.Context切换?,xaml,caliburn.micro,Xaml,Caliburn.micro,我的视图和viewmodels位于不同的项目中,我使用ViewLocator.AddNamespaceMapping调用映射所有内容 如何继续保持事物的独立性并使用视图。建议进行上下文切换 假设我的viewmodel项目包含顶级功能文件夹: MyViewModels/ --/FormDesigner/FormDesignerServiceModel.cs --/GroupDesigner/GroupDesignerServiceModel.cs --/FilterDesigner/FilterD
我将如何为每个当前Xaml视图的备用视图引入View.Context切换?谢谢我相信内置约定会为您解决问题。如果您的视图的名称空间/名称正确,您还可以指定其他约定 通常,如果您希望在以下结构中切换,您会放置视图:
Folder: Views/FormDesigner/ // Folder Structure not critical
NameSpace: YourApp.Views.FormDesigner
XAML: YourApp.Views.FormDesigner.Master.Xaml
XAML: YourApp.Views.FormDesigner.Detail.Xaml
Binding: <ContentControl cal:View.Model="{Binding Path=ActiveItem}"
cal:View.Context="Master" />
您的绑定可能会有所不同,对于切换,您需要将上下文绑定到ViewModel上的属性,该属性指示您的情况中的主属性或详细属性
可以使用现有视图,但如果要切换上下文,则必须从FormDesignerView.xaml更改名称
我在解释内置Caliburn时遇到了一个难题。在这个回答中,微观约定控制着这种行为:例如,假设每个视图有两个单独的上下文,例如主视图和详细视图。你是对的。我不需要做任何改变就能让它工作。实际上,我使用了名为HelloScreens的旧Silverlight CM示例,并将其分解为:-Caliburn.Micro.HelloScreens-Caliburn.Micro.HelloScreens.Framework-Caliburn.Micro.HelloScreens.ViewModels-Caliburn.Micro.HelloScreens.Views基本上将所有ViewModels移动到ViewModels项目,包括ShellViewModel,并将所有框架内容移动到框架项目中,包括IShell等。我必须将覆盖添加到引导程序中:好东西,很高兴它帮助了=D