Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 611
tbischel Avatar asked Oct 25 '10 18:10

tbischel


1 Answers

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; }
};
like image 131
devdigital Avatar answered Oct 23 '22 21:10

devdigital