WPF, Prism v2, Region in a modal dialog, add region in code behind

前端 未结 3 1102
清酒与你
清酒与你 2020-12-09 18:53

I have a composite WPF application. In one of my modules I want to make a wizard and have the steps show up in a region so I can switch between the steps easier. Originally

3条回答
  •  长情又很酷
    2020-12-09 19:32

    The problem is that regions search up the visual tree for the RegionManager attached property, and then register themselves with that manager. In the main window that's fine, but in a child window this doesn't happen.

    In the Bootstrapper, after the shell is created, the following code is performed.

    RegionManager.SetRegionManager(shell, this.Container.Resolve());
    RegionManager.UpdateRegions();
    

    To get the region manager to work with your child window do the same thing right after you've created the window.

    EDIT

    To set the region name of a control, you also set the attached property of the RegionManager, like so...

    RegionManager.SetRegionName(control, "MyRegion");
    

    However you can do this in xaml aswell. The reason why your regions in a separate window don't work is because the RegionManager needs to be set on the base window, like I showed above.

提交回复
热议问题