绑定到元组列表

发布于 2024-09-28 23:29:44 字数 174 浏览 3 评论 0原文

我有一个与两条数据配对的元组列表...我想将该列表绑定到数据网格。对于显示,它工作正常...但如果我尝试修改一个条目,它会显示“TwoWay 或 OneWayToSource 绑定无法在只读属性“Item1”上工作”...大概元组在 .NET 4.0 中是不可变的。有没有一种简单的方法可以绑定到数据对,而无需创建我自己的可变元组类?

I have a list of tuples pairing two pieces of data... I'd like to bind the list to a data grid. For display, it works fine... but if I try and modify an entry, it says "A TwoWay or OneWayToSource binding cannot work on the read-only property 'Item1'"... presumably Tuples are immutable in .NET 4.0. Is there an easy way to bind to pairs of data without creating a mutable tuple class of my own?

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

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

发布评论

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

评论(1

影子是时光的心 2024-10-05 23:29:44

是的,元组是不可变的。匿名类型也是不可变的。您应该使用自己的泛型类型:

public class Pair<T, U> 
{
     public Pair() {
     }

     public Pair(T first, U second) {
       this.First = first;
       this.Second = second;
     }

     public T First { get; set; }
     public U Second { get; set; }
};

Yes, tuples are immutable. Anonymous types are also immutable. You should use your own generic type:

public class Pair<T, U> 
{
     public Pair() {
     }

     public Pair(T first, U second) {
       this.First = first;
       this.Second = second;
     }

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