Conductor Inside of a Screen

Feb 3, 2011 at 2:43 PM

In a project I am working on, we are creating a wizard to walk users through a series of steps.  We have our wizard shell, which is a Conductor<Screen>.OneActive and has several steps that the user can navigate back and forth between.  On of the steps is kind of complicated and has the need to be able to conduct its own items.  What we are trying to do is have the step have a property that is a Conductor<Screen>.OneActive and set that to a content control on the step.  So something like below: 

 

public class Step2ViewModel : Screen
{
        private Step2InnerConductorViewModel _innerConductor;

        public Step2InnerConductorViewModel InnerConductor
        {
            get { return _innerConductor; }
            set
            {
                _innerConductor = value;
                NotifyOfPropertyChange(() => InnerConductor);
            }
        }
}
with the xaml being:

<ContentControl Name="InnerConductor" />

The conductor gets bound up correctly, but when I try to set ActiveItem on the innerConductor I am getting the following error.  Any advice would be appreciated.  I can create a sample of the problem if need be.
System.Reflection.TargetInvocationException was unhandled by user code
  Message=Exception has been thrown by the target of an invocation.
  StackTrace:
       at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
       at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
       at Caliburn.Micro.View.SetContentPropertyCore(Object targetLocation, Object view)
       at Caliburn.Micro.View.SetContentProperty(Object targetLocation, Object view)
       at Caliburn.Micro.View.OnModelChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
       at System.Windows.Data.BindingExpression.SendDataToTarget()
       at System.Windows.Data.BindingExpression.SourcePropertyChanged(PropertyPathListener sender, PropertyPathChangedEventArgs args)
       at System.Windows.PropertyPathListener.RaisePropertyPathStepChanged(PropertyPathStep source)
       at System.Windows.PropertyAccessPathStep.RaisePropertyPathStepChanged(PropertyListener source)
       at System.Windows.CLRPropertyListener.SourcePropertyChanged(Object sender, PropertyChangedEventArgs args)
       at System.Windows.Data.WeakPropertyChangedListener.PropertyChangedCallback(Object sender, PropertyChangedEventArgs args)
       at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
       at Caliburn.Micro.PropertyChangedBase.RaisePropertyChangedEventCore(String propertyName)
       at Caliburn.Micro.PropertyChangedBase.<>c__DisplayClass3.<NotifyOfPropertyChange>b__2()
       at Caliburn.Micro.Execute.<>c__DisplayClass2.<InitializeWithDispatcher>b__0(Action action)
       at Caliburn.Micro.Execute.OnUIThread(Action action)
       at Caliburn.Micro.PropertyChangedBase.NotifyOfPropertyChange(String propertyName)
       at Caliburn.Micro.ConductorBaseWithActiveItem`1.ChangeActiveItem(T newItem, Boolean closePrevious)
       at Caliburn.Micro.Conductor`1.Collection.OneActive.ActivateItem(T item)
       at ItemsControlIssue.Step2ViewModel.set_Selected(Step2DetailsViewModel value)
  InnerException: System.ArgumentException
       Message=Value does not fall within the expected range.
       StackTrace:
            at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
            at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
            at MS.Internal.XcpImports.SetValue(IManagedPeerBase doh, DependencyProperty property, Object obj)
            at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
            at System.Windows.DependencyObject.SetEffectiveValue(DependencyProperty property, EffectiveValueEntry& newEntry, Object newValue)
            at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
            at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
            at System.Windows.Controls.ContentControl.set_Content(Object value)
       InnerException: 




Thanks in advance,

Mike

Coordinator
Feb 3, 2011 at 3:02 PM

Two things.

1. Make sure that you instantiate the inner conductor. You will also need to activate it since it isn't technically hosted inside of another conductor.

or

2. You could just make your Step2ViewModel actually inherit from Conductor.Collection.OneActive. That is probably what I would do.

Feb 3, 2011 at 4:05 PM

Rob,

I changed the Step2ViewModel to be a Conductor<Step2DetailsViewModel>.Collection.OneActive and I am still getting the error.  

We have discovered that it works when Step2DetailsViewModel is not a descendent of screen.  I can send you a sample application it you want, I have one ready to go.

Thanks,

Mike

Coordinator
Feb 3, 2011 at 4:46 PM

Yes. Please send it to robertheisenberg at hotmail dot com