如何检查视图是否已添加到 PRISM 中的区域?

发布于 2024-10-02 15:35:17 字数 38 浏览 0 评论 0原文

我有一个区域,想要检查是否添加了特定的视图类型。我该怎么做呢?

I have a region and want to check whether a specific view type is added to it or not. How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你又不是我 2024-10-09 15:35:17

以下代码(使用 Linq)应该有用:

regionManager.Regions["RegionName"].Views.Any(v => v.GetType() == typeof(ViewType));

希望这有帮助,

The following code (using Linq) should be useful:

regionManager.Regions["RegionName"].Views.Any(v => v.GetType() == typeof(ViewType));

Hope this helps,

我做我的改变 2024-10-09 15:35:17

您可以使用以下方法检查视图是否已添加到区域。

var regionManager = Get reference to the region manager
bool viewHasBeenAdded = regionManager.Regions["Your region"].GetView("View Name") != null;

这是您想要的还是您实际上想要检查类型而不是视图名称?

You can check to see if a view has been added to a region using the following method.

var regionManager = Get reference to the region manager
bool viewHasBeenAdded = regionManager.Regions["Your region"].GetView("View Name") != null;

Is this what you want or are you actualy wanting to check for Type rather than View name?

樱娆 2024-10-09 15:35:17
object obj = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(cntrlName);

var checkIfAlreadyExists = 
RegionManager.Regions["ApplicationCoreRegion"].Views.Contains(obj);

if (checkIfAlreadyExists) {
    MessageBox.Show("Can not add this, because it is already shown");
} else {
    RegionManager.RegisterViewWithRegion("ApplicationCoreRegion", () => obj);
    RegionManager.Regions["ApplicationCoreRegion"].Activate(obj);
}
object obj = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(cntrlName);

var checkIfAlreadyExists = 
RegionManager.Regions["ApplicationCoreRegion"].Views.Contains(obj);

if (checkIfAlreadyExists) {
    MessageBox.Show("Can not add this, because it is already shown");
} else {
    RegionManager.RegisterViewWithRegion("ApplicationCoreRegion", () => obj);
    RegionManager.Regions["ApplicationCoreRegion"].Activate(obj);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文