The title kinda says it all, but let me explain it in more detail with examples.
Lets assume you want to create a CustomList for various reason.
For example:
public CustomList<T> : IList<T>
{
//all members from IList<T> are implemented and are working
}
Now you have a DataGrid which binds to this list
In Code behind of a XAML (WPF) file:
TestDataGrid.ItemsSource = new CustomList<Person>() { new Person(), new Person() };
Now you would assume the editing works fine since the Person class has no retriction what so ever and the IsReadOnly of the CustomList is set to false.
public class Person
{
public string Name { get; set }
}
But wait, the WPF DataGrid gives out the error Message: 'EditItem' is not allowed for this view.
Now if I change the implementation of my CustomList to this:
public CustomList<T> : IList
{
//all members from IList are implemented and are working
}
The editing works, but the behaviour or LINQ and IEnumerable extensions just sucks, because the GetEnumerator returns a non generic version so I am stuck with only objects and would need to cast to my desired class all the time.
Am I seeing something wrong or is there no good solution? I just want to have a editable (in WPF DataGrid) CustomList with Sort Functionality (not OrderBy - Sort in place).
Some parts of the WPF engine look for
IList
, notIList<T>
. SinceIList<T>
does not implementIList
, WPF is only aware that your list isIEnumerable
, notIList
. You should implement both interfaces. You should use explicit interface implementation to hide implementations that shouldn't be public on your object, e.g.