使用 Silverlight、PRISM 和 MVVM 进行动态控制显示

发布于 2024-08-16 23:53:43 字数 723 浏览 2 评论 0原文

在我正在创建的应用程序的框架中,我可以将多个“插件”添加到“工作区”中,可以根据需要重新排列它们并调整其大小。我希望每个插件都能够向 WorkspaceManager(通过 IWorkspaceManager 接口公开)类注册 WorkspaceParameters(所有插件共享的全局参数)。当插件注册全局参数时,WorkspaceManager 首先检查是否已注册同名参数,如果已注册,则插件只需订阅以在其更改时收到通知。如果尚未使用给定名称创建一个,则会创建一个新名称。 WorkspaceParameter 类当前如下所示:

public class WorkspaceParameter
{
    public string Label { get; set; }
    public Type ParameterType { get; set; }
    public object Value { get; set; }
}

然后,我在应用程序中有一个视图,我希望显示每个 WorkspaceParameter 以便用户能够更改值。 UI 应基于每个 WorkspaceParameter 的 ParameterType 成员,并且所有参数应显示在 StackPanel 中。例如,如果类型是日期时间,我想显示一个文本框,旁边有一个日历选择器。如果它是一个字符串,则为一个简单的文本框,旁边带有标签,最后,如果它是一个枚举类型,则为一个包含可用枚举选项的下拉列表。

如何利用 PRISM 和 MVVM 的原理来实现这个动态视图?

In a framework for an app that I'm creating, I can have multiple "plug-in" 's added to a "workspace", where they can be rearranged and re-sized as necessary. I want each plug-in to be able to register WorkspaceParameters (global parameters shared by all plug-ins) with a WorkspaceManager (exposed through IWorkspaceManager interface) class. When the plug-in registers a global parameter, the WorkspaceManager first checks if one with the same name as already been registered and if it has, the plugin just subscribes to be notified if it changes. If it one has not been created already with the given name, a new one is created. The WorkspaceParameter class currently looks like this:

public class WorkspaceParameter
{
    public string Label { get; set; }
    public Type ParameterType { get; set; }
    public object Value { get; set; }
}

I then have a view in the app that I want to display each WorkspaceParameter for the user to be able to change the value. The UI should be based on the ParameterType member of each WorkspaceParameter and all of the parameters should be displayed in a StackPanel. For example, if the Type is DateTime, I want to display a textbox with a calendar selector next to it. If it's a string, a simple Textbox with the label next to it, and lastly for now, if it's an enum type, a dropdown with the available enum options.

How can I implement this dynamic view using the principles of PRISM and MVVM?

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

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

发布评论

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

评论(1

吖咩 2024-08-23 23:53:43

我建议您查看 Glenn Block 的一系列博文。
在上一篇文章中,他重构了他的解决方案以使用 mvvm 模式。
他大量使用 MEF,这是一个可扩展性框架。

这是续集的第 5 篇,请阅读所有内容,它基本上可能就是您想要的内容。

http://msmvps.com/blogs/theproblemsolver/archive/2009/02/18/getting-started-with-the-repository-pattern-in-silverlight.aspx

I would recommend to look at a series of Blogpost by Glenn Block.
In the last article he refactored his solution to use the mvvm pattern.
He uses MEF heavily this is a framework for extensibilty.

This is No. 5 of a sequal please read all of them it could be basically what you were looking for.

http://msmvps.com/blogs/theproblemsolver/archive/2009/02/18/getting-started-with-the-repository-pattern-in-silverlight.aspx

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