WPF / Silverlight 中的设计时数据 - 如何正确使用包装类?

发布于 2024-09-28 17:30:59 字数 689 浏览 1 评论 0原文

我面临着“设计时支持”最佳实践的问题。我正在使用 PRISM,我的对象是由 DI 容器创建的。让我们假设以下简单场景:

我有一个对象工作流程。该工作流有多个属性,并且有一个提供工作流列表的 WorkflowProvider。

如果我设计 ListView 就没有问题。我使用 MainApplication 对象作为设计时数据上下文,并且我的列表绑定到属性“WorkflowList”。在我的实时应用程序中,我可以将数据上下文设置为适当的实现。

但我不知道如何处理单个工作流程视图

通常我会创建一个工作流对象作为设计时数据上下文。但是我的工作流对象不能单独创建(使用空构造函数),它必须是我的 WorkflowProvider 的属性。因此,我过去使用的一种方法是:

  • 为工作流编写一个虚拟子类
  • 在虚拟的空构造函数中,获取“真实工作流”
  • 将“真实工作流”的所有属性分配给我的虚拟类的属性
  • 使用实例我的设计时视图中的虚拟工作流程的

唯一原因是我不知道如何将设计时数据上下文设置为属性而不是对象。这是可能的,还是有其他有意义的方式。为了澄清,我知道我可以将“工作流程详细信息视图”中的网格绑定到属性,但随后我无法在不进行更改的情况下将详细信息视图用作列表视图中的数据模板。我希望你能解决我的问题:-)

克里斯

I am facing a problem of "design time support" best practices. I am using PRISM, and my objects are created by a DI container. Lets assume the following simple scenario:

I have an object workflow. This workflow has several properties, and there is a WorkflowProvider which provides a list of workflows.

If I design the ListView I do not have a problem. I am using a MainApplication object as design time data context, and my list binds to the property "WorkflowList". In my live application I can set the data context to the appropriate implementation.

But I do not know how to handle a single workflow view!

Normally I would create a workflow object as design time data context. But my workflow object can't be created on its own (with an empty constructor), it has to be a property of e.g. my WorkflowProvider. So one approach I used in the past was this:

  • Write a dummy subclass for workflow
  • In the empty constructor of the dummy, get the "real workflow"
  • Assign all properties of the "real workflow" to the properties of my dummy class
  • Use an instance of the dummy workflow in my design time view

The only reason for that is that I do not know how to set the design time data context to a property, instead of an object. Is this possible, or is there any other way which makes sense. To clarify, I know I could bind e.g. my grid in my "workflow details view" to a property, but then I could not use the details view without changes as a DataTemplate in my list view. I hope you got my problem :-)

Chris

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

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

发布评论

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

评论(1

残花月 2024-10-05 17:30:59

好的,
像往常一样,一点点思考和一个好的猜测解决了我的问题:

d:DataContext="{Binding WorkflowProvider.CurrentWorkflow}"

做到了这一点,并且在实时场景中将被忽略......

Ok,
like so often, a little bit thinking and a good guess solved my problem:

d:DataContext="{Binding WorkflowProvider.CurrentWorkflow}"

does the trick, and will be ignored in real time scenarios...

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