我在现有架构中有一个奇怪的场景,现在已经开发了一段时间。该体系结构使用View-First在自定义MS Office应用程序中支持Caliburn Micro,该应用程序在MS Office任务窗格中使用WPF内容。由于没有顶级Application对象,我在每个任务窗格中使用自定义Bootstrapper和一组代理顶级内容“hosts”。 View-First顶级主机是单个项目的每个Conductors。在应用程序启动时初始化主机后,我只需将单个子项导入每个主机,然后利用ViewModel-First方法编写每个任务窗格的内容。
我现在正尝试使用
的样式引入View Context切换以支持备用视图<ContentControl cal:View.Context="{Binding TaskPaneState}" cal:View.Model="{Binding}" />
其中TaskPaneState是我的Viewmodels上的一个可观察属性,可以解析为“最大化”或“最小化”。
我组织了视图文件夹来支持这些上下文,所以我有Minimized.xaml,Maximized.xaml等。
但是,在测试这种方法时,我现在在尝试解析/加载/绑定时遇到无限循环:
2014-03-24 14:52:23.5904|INFO|Caliburn.Micro.Action|Setting DC of Corp.Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-03-24 14:52:23.5904|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to Corp.Control.Design.Views.Book.BookDesignerView.
2014-03-24 14:52:23.6094|INFO|Caliburn.Micro.Action|Setting DC of Corp.Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-03-24 14:52:23.6094|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to Corp.Control.Design.Views.Book.BookDesignerView.
2014-03-24 14:52:23.6314|INFO|Caliburn.Micro.Action|Setting DC of Corp.Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-03-24 14:52:23.6314|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to Corp.Control.Design.Views.Book.BookDesignerView.
2014-03-24 14:52:23.6474|INFO|Caliburn.Micro.Action|Setting DC of Corp.Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-03-24 14:52:23.6474|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to Corp.Control.Design.Views.Book.BookDesignerView.
2014-03-24 14:52:23.6664|INFO|Caliburn.Micro.Action|Setting DC of Corp.Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-03-24 14:52:23.6664|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to Corp.Control.Design.Views.Book.BookDesignerView.
2014-03-24 14:52:23.6904|INFO|Caliburn.Micro.Action|Setting DC of Corp.Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-03-24 14:52:23.6904|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to Corp.Control.Design.Views.Book.BookDesignerView.
2014-03-24 14:52:23.7104|INFO|Caliburn.Micro.Action|Setting DC of Corp.Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-03-24 14:52:23.7104|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to Corp.Control.Design.Views.Book.BookDesignerView.
2014-03-24 14:52:23.7534|INFO|Caliburn.Micro.Action|Setting DC of Corp.Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-03-24 14:52:23.7534|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to Corp.Control.Design.Views.Book.BookDesignerView.
我对可能造成这种无限循环的原因感到茫然。
编辑:
所以我更新了我的解决方案以使用Caliburn Micro的2.0.x Beta版本,我的行为更好,但仍有些异常。循环仍然发生但不是无限的。我得到大约250多个循环,然后事情稳定下来,View加载。从我在调试器中可以看出,如果我在View.OnModelChanged和View.OnContextChanged上放置一个断点,调试器将在这两个断点之间翻转大约250次(见下面的日志)。我也尝试过为View.Context使用TwoWay绑定,但这似乎没什么区别......还在挠我的头......
这是最新的日志:
2014-04-01 11:57:53.0681|INFO|Caliburn.Micro.Action|Setting DC of .Control.AddIn.Views.ObjectNavigationTaskPaneHostView to .Control.AddIn.ViewModels.ObjectNavigationTaskPaneHostViewModel.
2014-04-01 11:57:53.0741|INFO|Caliburn.Micro.Action|Attaching message handler .Control.AddIn.ViewModels.ObjectNavigationTaskPaneHostViewModel to .Control.AddIn.Views.ObjectNavigationTaskPaneHostView.
2014-04-01 11:57:53.0741|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|ObjectNavigationTaskPaneHostViewModel OnViewLoaded
2014-04-01 11:57:53.0741|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|ObjectNavigationTaskPaneHostViewModel OnViewAttached
2014-04-01 11:57:53.0741|INFO|Caliburn.Micro.ConventionManager|ViewModel bound on ActiveItem.
2014-04-01 11:57:53.0741|INFO|Caliburn.Micro.Screen|Activating .Control.AddIn.ViewModels.ObjectNavigationTaskPaneHostViewModel.
2014-04-01 11:57:53.0891|INFO|.Control.AddIn.Views.TaskPaneHostView|Entering : ActivateContent
2014-04-01 11:57:53.0891|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|ObjectNavigationTaskPaneHostViewModel Queued content viewmodel ObjectNavigationViewModel
2014-04-01 11:57:53.0891|INFO|.Control.AddIn.Views.TaskPaneHostView|Exiting: ActivateContent
2014-04-01 11:57:53.1221|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|ObjectNavigationTaskPaneHostViewModel OnViewReady
2014-04-01 11:57:53.1221|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|ActivateItem(ObjectNavigationViewModel '.Control.ViewModels.ObjectNavigation.ObjectNavigationViewModel')
2014-04-01 11:57:53.1221|INFO|Caliburn.Micro.Screen|Activating ObjectNavigationViewModel '.Control.ViewModels.ObjectNavigation.ObjectNavigationViewModel'.
2014-04-01 11:57:53.1591|INFO|Caliburn.Micro.Action|Setting DC of .Control.Views.ObjectNavigation.ObjectNavigationView to ObjectNavigationViewModel '.Control.ViewModels.ObjectNavigation.ObjectNavigationViewModel'.
2014-04-01 11:57:53.1591|INFO|Caliburn.Micro.Action|Attaching message handler ObjectNavigationViewModel '.Control.ViewModels.ObjectNavigation.ObjectNavigationViewModel' to .Control.Views.ObjectNavigation.ObjectNavigationView.
2014-04-01 11:57:53.1591|INFO|Caliburn.Micro.ConventionManager|ContentTemplate applied to Items.
2014-04-01 11:57:53.1591|INFO|Caliburn.Micro.ConventionManager|SelectedItem binding applied to Items.
2014-04-01 11:57:53.1811|INFO|Caliburn.Micro.Screen|Activating ObjectTypeNavigationViewModel 'Browse CONTROL classes by Type'.
2014-04-01 11:57:53.3491|INFO|Caliburn.Micro.Action|Setting DC of .Control.Views.ObjectNavigation.ObjectTypeNavigationView to ObjectTypeNavigationViewModel 'Browse CONTROL classes by Type'.
2014-04-01 11:57:53.3491|INFO|Caliburn.Micro.Action|Attaching message handler ObjectTypeNavigationViewModel 'Browse CONTROL classes by Type' to .Control.Views.ObjectNavigation.ObjectTypeNavigationView.
2014-04-01 11:57:53.3661|INFO|Caliburn.Micro.Action|Attaching message handler ObjectNavigationViewModel '.Control.ViewModels.ObjectNavigation.ObjectNavigationViewModel' to .Control.Windows.Common.KCIContextMenu Items.Count:1.
2014-04-01 11:58:05.0291|INFO|.Control.AddIn.Views.TaskPaneHostView|Entering : DeactivateContent
2014-04-01 11:58:05.0291|INFO|.Control.AddIn.Views.TaskPaneHostView|Exiting: DeactivateContent
2014-04-01 11:58:08.2491|INFO|Caliburn.Micro.Action|Setting DC of .Control.AddIn.Views.DesignerTaskPaneHostView: Active Designer to .Control.AddIn.ViewModels.DesignerTaskPaneHostViewModel.
2014-04-01 11:58:08.2491|INFO|Caliburn.Micro.Action|Attaching message handler .Control.AddIn.ViewModels.DesignerTaskPaneHostViewModel to .Control.AddIn.Views.DesignerTaskPaneHostView: Active Designer.
2014-04-01 11:58:08.2511|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|DesignerTaskPaneHostViewModel OnViewLoaded
2014-04-01 11:58:08.2511|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|DesignerTaskPaneHostViewModel OnViewAttached
2014-04-01 11:58:08.2511|INFO|Caliburn.Micro.ConventionManager|ViewModel bound on ActiveItem.
2014-04-01 11:58:08.2511|INFO|Caliburn.Micro.Screen|Activating .Control.AddIn.ViewModels.DesignerTaskPaneHostViewModel.
2014-04-01 11:58:08.2511|INFO|.Control.AddIn.Views.TaskPaneHostView|Entering : ActivateContent
2014-04-01 11:58:08.2511|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|DesignerTaskPaneHostViewModel Queued content viewmodel BookDesignerViewModel
2014-04-01 11:58:08.2511|INFO|.Control.AddIn.Views.TaskPaneHostView|Exiting: ActivateContent
2014-04-01 11:58:08.2841|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|DesignerTaskPaneHostViewModel OnViewReady
2014-04-01 11:58:08.2841|INFO|.Control.AddIn.ViewModels.TaskPaneHostViewModel|ActivateItem(BookDesignerViewModel(Basic Budget Example))
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Screen|Activating BookDesignerViewModel(Basic Budget Example).
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Action|Setting DC of .Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to .Control.Design.Views.Book.BookDesignerView.
<snip around 500 lines>
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Action|Setting DC of .Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to .Control.Design.Views.Book.BookDesignerView.
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Action|Setting DC of .Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to .Control.Design.Views.Book.BookDesignerView.
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Action|Setting DC of .Control.Design.Views.Book.BookDesignerView to BookDesignerViewModel(Basic Budget Example).
2014-04-01 11:58:08.2841|INFO|Caliburn.Micro.Action|Attaching message handler BookDesignerViewModel(Basic Budget Example) to .Control.Design.Views.Book.BookDesignerView.
<View finally loads >
答案 0 :(得分:0)
所以你有一个名为BookDesignerViewModel的视图模型,我假设你有BookDesignerView作为你的视图。然后你有一个名为BookDesigner的文件夹(纯粹用于Views文件夹下的结构),该文件夹包含该BookDesigner文件夹中包含的Max / Min .xaml(缩短)文件?
其次你尝试过设置cal:View.Context =&#34; {Binding TaskPaneState, Mode = TwoWay }&#34; ?我知道在以前的答案中,你问为什么考虑到有关该物业的通知性质已经完成,说实话我没有多考虑因为它是我在学习时看过的例子的一部分CM,它是示例HelloScreens,它以完整的细节显示视图切换。
答案 1 :(得分:0)
我还在测试,但我相信至少有两个问题我已经解决了。
首先,在ContentControl上查看View附加属性的顺序似乎很重要。这是我正在使用的订单:
<ContentControl cal:View.Context="{Binding TaskPaneState}" cal:View.Model="{Binding}" />
我不需要在Context属性上使用TwoWay绑定。
此外,如果出于某种原因,View.OnModelChanged所看到的Context属性的值不会解析为与系统上的真实视图对应的视图,则父View可能是返回并导致递归。
目前我还在测试,但暂时看起来很稳定。