wpftoolkit
wpftoolkit copied to clipboard
Cancelling out of the collection editor will remove any child collections items
There is a bug in the CollectionControlDialog.Clone() method that results in collection items being removed.
This manifests itself when the user Cancels out of the collection editor, it will remove any child collections items.
Taking the sample app from this post https://github.com/xceedsoftware/wpftoolkit/issues/1689
- Go to the Item Collection.
- Add an item
- Go to its Item collection (MainSubItem).
- Add one or more entries.
- Ok back out (twice).
- go back into the Items collection, and its Items collection → the MainSubItem is still there.
- Cancel back out (twice).
- go back into the Items collection, and its Items collection → the MainSubItem is now empty.
This is using the latest release (4.3).
Issue is that the GetProperties() call in the Clone() method (on line 240) does not return anything.
var properties = sourceType.GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly );
Oddly, when I removed the BindingFlags filters, the returned properties all had those same BindingFlags.
I will attach the sample from @midspace, with the WPFToolkit v4.3 source included, with code that fixed this situation commented out (although its not the correct fix) - see line 240 in WpfApp1-xceed.propertygrid.bugs\wpftoolkit-master\ExtendedWPFToolkitSolution\Src\Xceed.Wpf.Toolkit\CollectionControl\ImplementationCollectionControlDialog.xaml.cs.
WpfApp1-xceed.propertygrid.bugs_WithXceedSource.zip
Thanks, Dan.
Thank you for pointing this out. We will have a look to fix this.
Update: have found that BindingFlags.DeclaredOnly is the problem. I.e. when I call the below it returns the expected result:
var properties = sourceType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
The is no inheritance in the view model, so DeclaredOnly should not cause them to be excluded?
Hi
The issue has been itendtified and fixed. It will be made available in v4.5.
Thank you
A very similar issue on the free 4.3 and 4.5 version (works just fine under 4.1):
Collections containing certain custom objects have the object values reset to default if you press Cancel / Esc instead of OK.
Here's an example of an affected class, I have a collection containing modifiers that first inherit from an 'AddXValue' type like Modifier_AddStatValue (which simply adds 2 more properties) and in turn inherits from a base that simply provides a method.
If I click OK, with or without any changes everything works fine. Cancel or ESC clear most of the values.
public class Modifier_AddStatValueSine : Modifier_AddStatValue
{
[Description("Amplitude of the sine wave that defines the modifier's value. Basically Y-axis scaling.")]
public double Amplitude { get; set; }
[Description("Frequency of the sine wave that defines the modifier's value. Basically X-axis scaling.")]
public double Period { get; set; }
[Description("Time offset in minutes of the sine wave that defines the modifier's value. Basically X-axis offset. (The Value property takes care of Y-axis offset.)")]
public double TimeOffset { get; set; }
public override double GetValue(IPerson per, StatusEffectInstance instance)
{
return Math.Sin(((Game.GameTime.CurrentTimestamp - instance.StartTimestamp) / Period - TimeOffset) * 2d * Math.PI) * Amplitude + Value;
}
}
Before:
After (only Amplitude remains, Period is the default 180). All of the Modifier_ types are affected:

Same for a List of DoubleRange (Inherits Range<T> of type double (properties Min / Max)), this one is easier to cut down and share, attached in a file: Range.txt