Silverlight 4 复选框列在数据源中没有基础属性?

发布于 2024-11-07 10:38:22 字数 359 浏览 3 评论 0原文

我想知道是否有办法与任何高级控件(GridView、ListView、Form View...进行交互),您可以显示项目列表并在每个项目旁边有一个复选框,但没有布尔值数据源中该复选框后面的属性?

更多关于你会如何读回它?这意味着如果有一些项目的复选框被选中并且您保存了这些项目的列表,那么在编辑选择时,您将如何将其填充回控件中(意味着绑定所有项目,创建网格,无论它是什么......并且仅“检查”所选项目)?

/* 编辑 */

这代表以下场景:事件和参与者之间存在多种关系。创建“参与者”记录时,您希望为尽可能多的可用事件注册它们...您希望显示所有事件,但能够一次选择其中一些事件。

/* 结束编辑 */

谢谢, 马丁

I was wondering if there is anyway to interact with any of the advanced controls, GridView, ListView, Form View... in a way where you can display a list of items and have a checkbox next to each item, but without having a Boolean property behind that checkbox in the data source?

More over how would you read it back? Meaning if there were some items with their checkbox checked and you saved a list of those, when editing the selection, how would you populate it back in the control (meaning bind all items, create the grid, whatever it is... and only "check" the items that were selected)?

/* EDIT */

This represents the following scenario: You have a meny-to-meny relationship between say events and participants. When creating the "participant" record, you want to register them for as many events as there are available... You want to display all events, but be able to select some of them at a time.

/* END EDIT */

Thanks,
Martin

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

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

发布评论

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

评论(1

静赏你的温柔 2024-11-14 10:38:22

我假设您的数据源是一个模型(DTO 或将数据从服务器传输到客户端的其他方式)。如果这是真的,您可以将模型包装在另一个具有 IsSelected 属性的对象中。然后您可以绑定到扩展属性列表。我听说这被描述为面向方面的编程。当您从服务加载数据时,循环并创建扩展器,根据您的条件设置 IsSelected 并传入模型。然后将复选框绑定到 IsSelected 属性。

例子:

public class ModelExtender<T>
{
public T Model;
private bool isSelected = false;
public bool IsSelected
{
   get { return this.isSelected; }
   set
   {
       this.isSelected = value;
       this.RaisePropertyChanged("IsSelected");
   }
}

public ModelExtender(T model)
{
   this.Model = model;
}

I'm assuming your DataSource is a Model (a DTO or other way to transfer data from the server to the client). If this is true, you can wrap your model in another object, that has a IsSelected property. You can then bind to a list of extended attributes. I've heard this described as Aspect Oriented Programming. When you load up the data from your service, loop through and create the extender, setting the IsSelected based on your criteria and passing in the model. Then bind the checkbox to the IsSelected property.

example:

public class ModelExtender<T>
{
public T Model;
private bool isSelected = false;
public bool IsSelected
{
   get { return this.isSelected; }
   set
   {
       this.isSelected = value;
       this.RaisePropertyChanged("IsSelected");
   }
}

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