Hi,
You need to write below code before switching the view (before opening a form)
You can use below code to display the taskpane:
HTMLTaskPane taskPane = (HTMLTaskPane)thisXDocument.View.Window.TaskPanes[0];
taskPane.Visible = true;
You can use below code to hide the taskpane:
HTMLTaskPane taskPane = (HTMLTaskPane)thisXDocument.View.Window.TaskPanes[0];
taskPane.Visible = false;