How can I tell the ListCollectionView that Telerik PropertyGrid uses?
I am using PropertyGrid to view, edit, add and remove property values โโof an outer class that I cannot change. Class contains many properties List<string>
, List<int>
, List<Guid>
so I can not add value to these lists by using the PropertyGrid, because he does not know how to create them.
So my initial idea was to wrap each type using a class that looks like this:
public class ValueOf<T>
{
public T Value { get; set; }
public ValueOf()
{
Value = default(T);
}
public ValueOf(T valueContent)
{
Value = valueContent;
}
}
... but that means I'll have to use the View Model for this class. I cannot modify and write each property like this:
public ObservableCollection<ValueOf<string>> Names{ get; set; }
So I searched a little more and found this link: http://www.michaelruck.de/2012_07_01_archive.html
It talks about writing a custom ListCollectionView to add to work in the DataGrid, but that looks like it would work for PropertyGrid as well. Something seems to like this:
public class TypedListCollectionView<T> : ListCollectionView, IEditableCollectionView
{
private Func<T> factory;
public TypedListCollectionView(IList collection, Func<T> factory)
: base(collection)
{
this.factory = factory;
}
bool IEditableCollectionView.CanAddNew
{
get
{
return this.CanAddNewItem;
}
}
object IEditableCollectionView.AddNew()
{
T obj = this.factory();
return this.AddNewItem(obj);
}
}
My question is, how can I tell which ListCollectionView the PropertyGrid should use? I'm new to WPF and it seems like I am missing something.
No one has answered this question yet
Check out similar questions: