Smartpart (re)activation problem

Topics: CAB & Smart Client Software Factory
Nov 25, 2006 at 1:23 AM
originally posted by: bprobst

We use several workitems with the outlookbar in a deckworkspace. Each workitems has several smartpart (views), that show up inside the shell right workspace or as a modal dialog. To display a specifig view on a command action we use code like this:

EditView eView;
WorkItem.WorkspacesConstants.WorkspaceNames.RightWorkspace.Show(
( eView = WorkItem.SmartParts.Get<EditView>( "EditView" ) )
?? ( eView = WorkItem.SmartParts.AddNew<EditView>( "EditView" ) )
);

Now, the OnLoad will only be called once - but how can different data be presented ???

OK, one solution was adding code to remove the view from the smartparts collection immediately after the lines above,
which will continue to show the view:

WorkItem.SmartParts.Remove( eView );

Now, the OnLoad will be called on every command action - but will result in a lot of such views.
So, is there a chance of finding the still open view, bring it in front and filling in new data ???

BTW: While debugging we found that the Remove(eView) will NOT remove the corresponding presenter from the internal
collections (see: //((Microsoft.Practices.ObjectBuilder.LifetimeContainer)(WorkItem.SmartParts.container)).items) and all pressenters will
accummulate there in increasing numbers.
To remove them one could include after implementing the get Presenter inside the view.:

WorkItem.SmartParts.Remove( eView.Presenter );


A lot of questions - any remark welcome
Jan 4, 2007 at 11:55 PM
originally posted by: RobertEwen

Hi,

just try this.

void ShowEditView()
{
EditView eView;
WorkItem.WorkspacesConstants.WorkspaceNames.RightWorkspace.Show(
( eView = WorkItem.SmartParts.Get<EditView>( "EditView" ) )
?? ( eView = WorkItem.SmartParts.AddNew<EditView>( "EditView" ) )
);

eView.UpdateSomething();
}

Have a look at the MVC or MVP patterns, to choose the right UpdateMechanism. But in fact you do not have to use the OnLoad method to present data ...
Feb 10, 2007 at 1:54 PM
Edited Feb 10, 2007 at 1:58 PM
Feb 10, 2007 at 1:54 PM
Hello RobertEwen,
I'm not sure I understand what you mean by the above. i.e. eView.UpdateSomething()
what am I supposed to update?
Feb 12, 2007 at 7:02 AM
I don't know if I've understood your question.

Dou you want to "bring to front" a SmartPart wich is already launched in a workitem??

I have an application with an outlook bar too, and lots of views/workitems, and i launched each workitem once. If user doesn't close this workitem and click again in one of the lauched one I only check if that workitem exists in the items collection, and if exists i've call the workitem.Activate() method.

Also, in the workitem definition, i add the workitem.activating event, and in this event I recover the smartparts and show it.

I hope this will help you.