从 Silverlight PRISM 中的区域删除视图

发布于 2024-08-04 21:21:25 字数 131 浏览 1 评论 0原文

我有一个区域一次只能有一个活动视图。我想根据用户操作向该区域添加新视图,并从同一区域删除现有视图。我还想维护一些视图的缓存。如果视图数量超过指定的限制,那么我将删除最旧的视图。是否有任何直接支持,或者我必须为其实现区域适配器。还有其他更好的方法吗?

I have a Region which can have only one active view at a time. I want to add new view to the region on user action and remove the existing view from the same region. I also want to maintain the cache of few views. If the no of view is more than the specified limit then I will remove the oldest view. Is there any direct support for it or I have to implement the Region adapter for it. Is there any other better approach for the same?

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

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

发布评论

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

评论(2

莫言歌 2024-08-11 21:21:25

好吧,让我回答你的两个问题。

首先,如果您希望某个区域仅显示一个视图(例如您将一个区域定义为 ContentControl),这是可能的。您可以向该区域添加多个视图,并且仅显示活动视图。要在已添加的区域中显示不同的视图,您只需激活该视图即可:

var region = regionManager.Regions["TabRegion"];

region.Add(view1);
region.Add(view2);

region.Activate(view2);

通过这种方式,您可以拥有许多准备就绪的实例化视图,但只有一个可见。

其次,随着到期日。我想说区域适配器将是最干净、最正确的方法,但是您可以为这些创建一个过期的缓存,当它们过期时,您可以将它们从区域中删除(如果它们不是) active:

var region = regionManager.Regions["TabRegion"];

region.Add(view1);
regionTracker.Add(view1, region, TimeSpan.FromMinutes(10));
region.Add(view2);
regionTracker.Add(view2, region, TimeSpan.FromMinutes(10));

region.Activate(view2);

然后你的regionTracker的过期实现可能只是:

if(!region.ActiveViews.Contains(ViewThatJustExpired))
{
     region.Remove(ViewThatJustExpired);
}

它有点不成熟,但希望这能让你知道该去哪里。

Well, let me answer your two questions.

First, if you want a Region to only show one view (like say you have a region defined as a ContentControl), that is possible. You can add many views to that region and only the active one will be shown. To show a different view in that region that has already been added, you would simply Activate that view:

var region = regionManager.Regions["TabRegion"];

region.Add(view1);
region.Add(view2);

region.Activate(view2);

In this way, you can have many instantiated views ready to go, but only one visible.

Second, with the expirations. I'd say a region adapter would be the cleanest and most correct way, but you could just create an expiring cache for these and when they expire, you can remove them from the region if they aren't active:

var region = regionManager.Regions["TabRegion"];

region.Add(view1);
regionTracker.Add(view1, region, TimeSpan.FromMinutes(10));
region.Add(view2);
regionTracker.Add(view2, region, TimeSpan.FromMinutes(10));

region.Activate(view2);

And then the implementation of your expiration for your regionTracker could just:

if(!region.ActiveViews.Contains(ViewThatJustExpired))
{
     region.Remove(ViewThatJustExpired);
}

It's a bit half-baked, but hopefully this will give you some idea of where to go.

遇到 2024-08-11 21:21:25

请参阅我的博客文章,了解如何通过导航在 PRISM 中动态加载模块。在那篇文章中,您将看到我如何使用多视图容器,然后将视图交换到焦点和焦点之外。它涉及有一个导航界面,然后引发使用视觉状态管理器交换视图状态的事件。

单击此处查看

杰里米

Take a look at my blog post about dynamic module loading in PRISM with Navigation. In that post you'll see how I use a multiple-view container, then swap views into and out of focus. It involves having an interface for navigation, then raising events that swap the view state using the visual state manager.

Click Here to View

Jeremy

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文