开发者

Prism 4: How to hide items in an ItemsControl?

I am creating a Prism 4 demo app to learn the new framework, focusing on view-switchin开发者_开发百科g. The app has several regions, one of which is an ItemsControl that holds one or more buttons from the currently-active module.

I am registering the buttons with the Region Manager in each module's Initilize() method. Here is the registration code for the first module:

RegionManager.RegisterViewWithRegion("ButtonRegion", typeof(ModuleAButton1));
RegionManager.RegisterViewWithRegion("ButtonRegion", typeof(ModuleAButton2));

The second module registers its buttons the same way. I use RequestNavigate() to switch between the two modules.

Here's my problem: The buttons from both modules are visible in the ItemsControl, instead of just the buttons from the active module. I considered changing the ItemsControl to a ContentControl and putting the buttons in a StackPanel, but for reasons I won't bore you with here, that won't work for me. What I need to do is either:

  • Load the buttons when a module is activated, and unload them when I switch to the other module, or

  • Show the buttons when a module is activated, and hide them when I switch to the other module.

How do I do that in Prism 4? Thanks for your help.


I found my answer. Implement the IRegionMemberLifetime interface on the view or its view model. The interface is made up of a single read-only boolean property, KeepAlive. If the property is set to true, the view will be kept alive after the user navigates away from it. If the property is set to false, the view will be unloaded. See the "Developers Guide to Microsoft Prism" (Ver 4), p. 121.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜