void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { UserControl newPanel = null; switch (e.Node.Index) { case 0: newPanel = new UserControl1(); break; case 1: newPanel = new UserControl2(); break; // etc... } if (newPanel != null) { if (mActivePanel != null) { mActivePanel.Dispose(); this.Controls.Remove(mActivePanel); } newPanel.Dock = DockStyle.Fill; this.Controls.Add(newPanel); this.Controls.SetChildIndex(newPanel, 0); mActivePanel = newPanel; } }
public MainViewModel() { View = new UserControl2(); }
// or if you want the exact types: // UserControl1 control1; // UserControl2 control2; public ProfileWindow() { control1 = new UserControl1(); control2 = new UserControl2(); }