Frage

I have a curious scenario in an existing architecture that has been in development for a while now. The architecture uses View-First to support Caliburn Micro inside a custom MS Office app that uses WPF content in MS Office Task panes. Since there is no top-level Application object, I use a custom Bootstrapper and a set of surrogate top-level Content "hosts" inside each Task Pane. The View-First top-level hosts are each Conductors of a single item. Once the hosts are initialized when the application starts, I simply conduct single child into each one and from that point on utilize ViewModel-First approach to compose the content of each Task Pane.

I am now trying to introduce View Context switching to support alternate views, using the style of

<ContentControl cal:View.Context="{Binding TaskPaneState}" cal:View.Model="{Binding}" />

Where TaskPaneState is an observable property on my Viewmodels that can either resolve to "Maximized" or "Minimized".

I organized the view folders to support these contexts, so I have Minimized.xaml, Maximized.xaml, etc.

However, when testing this approach I am now getting an infinite loop when trying to resolve/load/bind:

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.

I'm at a loss at to what might be causing this infinite looping.

EDIT:

So i've updated my solution to use the 2.0.x Beta version of Caliburn Micro, and I get better behavior, but still aberrant somewhat. The looping still occurs but not infinitely. I get about 250+ loops and then things settle down and the View loads. From what I can tell in the debugger, if I put a breakpoint on View.OnModelChanged and View.OnContextChanged, the debugger flips between these two breakpoints about 250+ times (seen in the log below). I've also tried using a TwoWay binding for View.Context but that seems to make no difference... Still scratching my head...

Here's latest log:

    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 >
War es hilfreich?

Lösung 2

I'm still testing, but I believe there were at least two problems that I have addressed.

First the ordering of the View's attached properties on the ContentControl seems to be important. This is the order I am using:

<ContentControl cal:View.Context="{Binding TaskPaneState}" cal:View.Model="{Binding}" />

I didn't need to use a TwoWay binding on the Context property.

Also, if for some reason the value of the Context property, as seen by the View.OnModelChanged doesn't resolve to a view that corresponds to a real view on your system, it is possible that the parent View is returned and causes recursion.

Currently I'm still testing but it looks stable for the time being.

Andere Tipps

So you have a viewmodel named BookDesignerViewModel and I assume you have BookDesignerView as your view. Then you have a folder called BookDesigner (purely for structure under the Views Folder) that has Max/Min .xaml (shortened) files contained in that BookDesigner folder?

Secondly have you tried settings the cal:View.Context="{Binding TaskPaneState, Mode=TwoWay}" ? I know in previous answers you asked why it was done considering the nature of notification to that Property in question, to be honest I hadn't put much thought into it because it was part of the examples that I had looked over while learning CM, it was example HelloScreens that shows view switching in full detail.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top