Hybrid example, ActivateItem

Jan 31, 2011 at 9:48 PM

In the Hybrid example DocumentWorkspace class there is a Show method which calls Parent.ActivateItem. Before Parent seems to be of type IConductor in the Screen class but it's now of type object. What should Show call instead of Parent? Or maybe there is an updated sample?


public void Show() {
  if(Parent.ActiveItem == this) {
    DisplayName = IconName;
    State = DocumentWorkspaceState.Master;

Jan 31, 2011 at 9:53 PM

All the samples are now under source. Have a look there. Some changes have been made.

Jan 31, 2011 at 11:47 PM

Ever since the refactor of Parent as an object I've added the following to my screen base class:


public bool TryActivateItem(object item)
            if (Parent == null) return false;

            if (item == null) return false;

            var iConductActiveItem = Parent as IConductActiveItem;

            if (iConductActiveItem == null) return false;


            return true;

Feb 1, 2011 at 12:24 AM

Hi Joe 

Is it ok to do that ? ... won't it add the item to the parent's Items ? or is that what you're intending it to do 


Sorry if that seems like a daft question - I'm half asleep ;-)



Feb 1, 2011 at 4:56 AM

Nope, ActivateItem isn't doing any instance resolve/creation is takes an existing instance of an object to activate on a conductor. My code is a bit tangental to the original question though. All my code does is attempt to caste the parent as something that conducts an active item (Implements IConductActiveItem) and activates it through the Parent, if Parent is null or can't be caste then my method returns false. It's a safe way to try to activate without throwing on failure (though some people may want to throw). Rob's new code in the Hello Screens examples uses a property getter that castes the Parent:

protected IConductor Conductor { get { return (IConductor)Parent; } }

Which will throw if Parent is null or isn't casteable as a IConductor (which may be what you want).