Prism 4:如何隐藏 ItemsControl 中的项目?
我正在创建一个 Prism 4 演示应用程序来学习新框架,重点是视图切换。该应用程序有多个区域,其中之一是 ItemsControl,它包含当前活动模块中的一个或多个按钮。
我在每个模块的 Initilize()
方法中向区域管理器注册按钮。这是第一个模块的注册代码:
RegionManager.RegisterViewWithRegion("ButtonRegion", typeof(ModuleAButton1));
RegionManager.RegisterViewWithRegion("ButtonRegion", typeof(ModuleAButton2));
第二个模块以相同的方式注册其按钮。我使用 RequestNavigate()
在两个模块之间切换。
这是我的问题:两个模块中的按钮在 ItemsControl
中都可见,而不仅仅是活动模块中的按钮。我考虑过将 ItemsControl
更改为 ContentControl
并将按钮放入 StackPanel
中,但由于我不会在这里让您感到厌烦,所以对我不起作用。我需要做的是:
在激活模块时加载按钮,并在切换到另一个模块时卸载它们,或者
激活一个模块时显示按钮,切换到另一个模块时隐藏它们。
我该如何在 Prism 4 中做到这一点?感谢您的帮助。
I am creating a Prism 4 demo app to learn the new framework, focusing on view-switching. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案。在视图或其视图模型上实现 IRegionMemberLifetime 接口。该接口由单个只读布尔属性
KeepAlive
组成。如果该属性设置为true
,则在用户离开视图后视图将保持活动状态。如果该属性设置为false
,视图将被卸载。请参阅“Microsoft Prism 开发人员指南”(第 4 版),第 11 页。 121.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 totrue
, the view will be kept alive after the user navigates away from it. If the property is set tofalse
, the view will be unloaded. See the "Developers Guide to Microsoft Prism" (Ver 4), p. 121.