Behaviour of ShowViewInWorkspace

Topics: CAB & Smart Client Software Factory
Jul 5, 2007 at 8:18 AM
The ShowViewInWorkspace(string viewId, string workspaceName) method in the WorkItemController does not include the viewId in the AddNew<TView>() call. This means that the newly created view (as a result of AddNew) is not associated with the ID passed in viewId so you cannot expect to find the view again using viewId. This overload of the ShowViewInWorkspace method tries to do precisely that. i.e. Find a view by viewId and then show it if it exists.

This means that repeated calls to ShowViewInWorkspace() results in new instances of the view being created.

ShowViewInWorkspace<SearchCustomerView>("CustomerSearchViewId", "mainworkspace"); // 1
ShowViewInWorkspace<SearchCustomerView>("CustomerSearchViewId", "mainworkspace"); // 2

results in 2 SearchCustomerView instances being created because the first instance was not added to the WorkItem with the "CustomerSearchViewId".

Is this expected behaviour or a bug in ShowViewInWorkspace() ?
Jul 5, 2007 at 3:16 PM
Edited Jul 5, 2007 at 3:19 PM
It looks like you are right and is not working as expected. A quick fix would be to call the AddNew (inside the WorkItemController’s overloaded ShowViewInWorkspace implementation) passing the viewId argument. The method would then look like:

protected virtual TView ShowViewInWorkspace<TView>(string viewId, string workspaceName)
TView view = default(TView);
if (WorkItem.SmartParts.Contains(viewId))
view = WorkItem.SmartParts.Get<TView>(viewId);
view = WorkItem.SmartParts.AddNew<TView>(viewId);


return view;

Hope it helps!

Luciano G. Panaro
Jul 6, 2007 at 8:08 AM
Hi Luciano,

Thanks for your feedback.

I have already implemented the solution that you suggest. I wanted to get a general consensus from the community on whether or not it is a bug or expected behavior.

Thanks again.

Bye for now,