Dockable WPF windows

Viewed 39

I am creating an application which has multiple child and one parent form. Parent form will contain a Menu ribbon and the content of any one of the child forms. I want to give the user the freedom to select any one of the child form so that it can be docked onto the main form. The child form can be popped out any time during runtime and the user should have the choice to change the child form being used. Is there any way to achieve this in WPF?

I know a bit about UserControl and how they can be used inside other controls. Is that a good way to do it? Or are there better options available?

1 Answers

If you are new to WPF, I'd suggest you use Prism, run this simple sample and see how easy navigation is.. These are the steps..

  1. Define your view (pseudo-code)
<MyView xmlns:prism="http://prismlibrary.com/">
   <DockPanel>
      <Ribbon DockPanel.Dock="Top"/>
      < !-- This CenterRegion will be below the ribbon -->
      <ContentControl prism:RegionManager.RegionName="CenterRegion" />
</MyView>
  1. Register your view for navigation in your project (you ought to see the sample app I've attached to get to know where does this code lay)
// Prism Service
public void RegisterTypes(IContainerRegistry containerRegistry)
{
    // View.xaml
    containerRegistry.RegisterForNavigation<ViewA>();
   
    // ViewB.xaml
    containerRegistry.RegisterForNavigation<ViewB>();
}
  1. Change the Content of CenterRegion when user clicks a ribbon button
  • Show ViewA on ribbon button click
// RegionManager from Prism services
RegionManager.RequestNavigate("CenterRegion", "ViewA");
  • Show ViewB on another ribbon button click
RegionManager.RequestNavigate("CenterRegion", "ViewB");
Related