开发者

binding to a list of tuples

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 r开发者_运维知识库ead-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?


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; }
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜