使用 Silverlight DataForm 和 .Net RIA Services DomainDataSource 时如何设置初始值?
我正在尝试 .Net RIA 和 Silverlight,我有一些相关的实体;客户、项目和工作,一个客户有很多项目,一个项目有很多工作。
在 Silverlight 应用程序中,我使用 DomainDataSource 和 DataForm 控件来执行 CRUD 操作。选择客户后,会出现一个项目列表,此时用户可以为该客户添加新项目。我希望能够自动填写客户端的值,但似乎没有任何方法可以做到这一点,虽然 DataForm 控件上有一个 AddNewItem 事件,但它似乎在 DataForm 具有之前触发新对象的实例,我不确定从 DomainDataSource SubmittingChanges 事件中搜索 ChangeSet 是执行此操作的最佳方法。
我认为这将是一个明显的功能...有人知道实现此功能的最佳方法吗?
I'm experimenting with .Net RIA and Silverlight, I have a few of related entities; Client, Project and Job, a Client has many Projects, and a Project has many Jobs.
In the Silverlight app, I'm uisng a DomainDataSource, and DataForm controls to perform the CRUD operations. When a Client is selected a list of projects appears, at which point the user can add a new project for that client. I'd like to be able to fill in the value for client automatically, but there doesn't seem to be any way to do that, while there is an AddingNewItem event on the DataForm control, it seems to fire before the DataForm has an instance of the new object and I'm not sure trawling through the ChangeSet from the DomainDataSource SubmittingChanges event is the best way to do this.
I would of thought this would of been an obvious feature... anyone know the best way to achieve this functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,聚会迟到了,但面对同样的问题,我使用值转换器实现了一个解决方法:
它将缺失的日期值(例如 01.01.0001)转换为今天的日期,并允许使用
参数添加/减去天数
-参数。Well, being late for the party but facing the same issue I implemented a workaround using a value converter:
It translates missing date values (e.g. 01.01.0001) to today's date and allows adding/subtracting days using the
parameter
-parameter.通常做的事情是拥有一个包含显示现有数据的 DataGrid 的屏幕。然后有一个添加按钮,它将:
Something that is commonly done is to have a screen that contains a DataGrid showing the existing data. Then have an Add button that will:
为了在创建实体时设置默认值,我添加了一个名为 [EntityName].shared.cs 的类。然后我使用了链接中拼写的技术。这对我来说效果很好。
To set default values as my entity is created I added a class called [EntityName].shared.cs. I then used the technique spelled at this link. It worked well for me.
此解决方案允许您在集合末尾添加新项目。该集合绑定到 DataForm。在退出当前处理程序之前,将 DataForm.CurrentIndex 设置为集合中的最后一项,然后取消添加过程。新项目已初始化/添加并在数据表单中可见,可供编辑。
This solution allows you to add a new item at the end of a collection. The collection is bound to DataForm. Before exiting the current handler, set the DataForm.CurrentIndex as the last item in collection then cancel the adding procedure. The new item is initialized/added and visible in Dataform ready for editing.