Search code examples
cabscsf

SCSF: display view from another view against button click


i am facing one problem in SCSF.

I have two workspaces

  1. MdiWorkspace
  2. DeckWorkspace

i have two views in a module

  1. Viewer (display in mdiworkspace)
  2. Property Viewer (in deckworkspace)

in Viewer i have a button in toolbar whose purpose is to display PropertyViewer (another View).

how can i display this PropertyViewer in deckworkspace agaist button click event.

NOTE: i am not using Command[CommandName].AddInvoker(control, "click:) and CommandHandler


Solution

  • I'm going to assume your toolbar sits in a SmartPart that implements the MVP pattern. Have the button click event handler in the SmartPart fire an event that its presenter will handle. Your presenter code would look like this:

    // Presenter code
    
    protected override void OnViewSet()
    {
       this.View.ToolbarButtonClick += View_ToolbarButtonClick;
    }
    
    public void View_ToolbarButtonClick(object sender, EventArgs e)
    {
        // remove the handler so the property viewer 
        // will only be added the first time
        this.View.OnToolbarButtonClick -= View_ToolbarButtonClick;
    
        var propertyView = new PropertyViewer();
        this.WorkItem.Workspaces[WorkspaceNames.MyDeckWorkspace].Show(propertyView);
    }