Modal Workspace

Topics: CAB & Smart Client Software Factory
Nov 13, 2006 at 9:04 PM
originally posted by: surajguptha

I am poping a window up using modal workspace. How do i return some data to the parent screen on click of the close button on the popup?

Feb 20, 2007 at 11:36 AM
Best is to call your presenter and have it store your data in your WorkItem.
_presenter.SetData(PopupData d);

The presenter then does
WorkItem.State"PopupData" = d;

thus making it available to all smartparts that use this WorkItem (which is usually all smartparts operated by the same ModuleController).

Hope that helps !
Best regards
Feb 20, 2007 at 5:55 PM
This is a tough issue to deal with because if you call View.OnCloseView() then that tells the Workspace to Close() the view, which disposes it, which is typically not what you want to do (because then you can't fetch data from the popup via properties).

I've got a big blog post on this issue coming up describing how we solved this problem where I work. We've created a base class called DialogBox that is CAB-friendly and allows you to treat UserConrols + WindowWorkspace like a standard Modal dialog without causing it to popup during unit testing scenarios (and it returns a DialogResult and allows you to pick data off the Dialog with properties). We've also created a custom MessageBox class, again CAB-friendly, which works like a standard MessageBox but it is a UserControl that uses the WindowWorkspace instead, so it too can be made to not popup during unit testing.

I'll post here when the blog post is up, hopefully tonight. We think our solution is pretty neat and we hope it helps the community.
Feb 20, 2007 at 8:59 PM
That's definitely true. It needs to be noticed that indeed, it's not possible to get back any information from the Control. Strangely enough, it's still present in the SmartParts property of the WorkItem. But accessing it returns a 'Accessing a disposed object' exception - as opposed to having been removed from the SmartParts collection. So when closing and later reopening it, I remove it first of it's still around; and then reopening it. That seems to be caused by a bug/strange behaviour related to the WindowWorkspace.

Thanks Chris !

I shall be looking forward to your blog entry already - i haven't had enough time to come up with a proper solution/workaround, and thus really look forward to your promising sounding solution !

Apr 27, 2007 at 2:19 PM

gdngenericuser wrote:
originally posted by: surajguptha

I am poping a window up using modal workspace. How do i return some data to the parent screen on click of the close button on the popup?


I have been trying to create modal dialogs in CAB, but without using SmartParts - and I guess that is not the way to got. Where can you find this "modal workspace"? Is it in a quite recent release of CAB?
Apr 27, 2007 at 7:43 PM
My preference is to treat all Views the same. All data is handled via the Presenter and the WorkItem as denisabt suggests. Notification (in this case to "the parent screen") is handled by an Event Publication. The parent screen subscribes to the event and gets data required from the WorkItem. In certain circumstances, the data object can be sent as an EventArg with the Event Publication. In this way, the View can be moved into any WorkSpace appropriate to the UI and all Views and Presenters have the same behavior that is independent of the UI du jour.

As for the Modal WorkSpace, I add it in ShellApplication.AfterShellCreated
// Add window workspace to be used for modal windows
WindowWorkspace wsp = new WindowWorkspace();
RootWorkItem.Workspaces.Add(wsp, WorkspaceNames.ModalWindows);