Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Closed Issue: PropertyGrid Collection Editor Cannot Handle Inherited Properties/Fields Properly [19682]

$
0
0
When the built in Collection Editor loads an existed item in a collection, it tries to clone the item by copying all its fields to a new item, while the latter one will be edited in the editor. However, the Xceed.Wpf.Toolkit.CollectionControl.CopyValues method only copies the fields declared in the Type which the item to clone is, not with those in its base class(es).

Here is the revised implementation, feel free to use it if it helps.

```
private static void CopyValues(object source, object destination)
{
LinkedList<Type> types = new LinkedList<Type>();
var type = source.GetType();
while (type != null)
{
types.AddFirst(type);
type = type.BaseType;
}

foreach (var t in types)
{
FieldInfo[] myObjectFields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (FieldInfo fi in myObjectFields)
{
fi.SetValue(destination, fi.GetValue(source));
}
}
}
```
Comments: Duplicate of
https://wpftoolkit.codeplex.com/workitem/18206

This is fixed in version 2.0

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>