Editor used in CollectionNewItem

Editors for WPF Forum

Posted 6 years ago by Antoine Picard
Version: 18.1.0672
Avatar

Hi !

I saw there is an editor for list such as the one used in the grid sample, but I'm not able to find it in editors sample. Waht is the name of this editor ?

I have a specific class and I would like to use this editor for it.

Thanks !

AP

Comments (17)

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Antoine,

We don't really have an editor dedicated to lists.  If you give me an exact example of what you're referring to in one of our samples, I can give you more information on what it is.


Actipro Software Support

Posted 6 years ago by Antoine Picard
Avatar

Hi,

I was thinking about the example in the Grids sample called "Collection New Items". 

I checked the code and wasn't able to find any particular thing to display "Strings1", "Strings2" and "Strings3". There is the type converter but I don't think it's responsible of the display.

Thanks

AP

Posted 6 years ago by Antoine Picard
Avatar

Ok so I managed to make it work by adding CollectionPropertyDisplayMode="EditableInline" to my PropertyGrid but my objects inside my list can't be removed and adding a new object doesn't trigger the PropertyValueChanged event.

Any tip or any idea why ?

AP

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Antoine,

Unfortunately that UI (the add/remove from collection buttons) is a feature of the PropertyGrid and isn't a standalone Editors control.

For PropertyGrid collection editing, please check out the "Collections" topic in the PropertyGrid documentation that comes with the product.  That talks about the CollectionPropertyDisplayMode property and covers other things like special events specifically for handling the adding/removing of collection items.


Actipro Software Support

Posted 6 years ago by Antoine Picard
Avatar

Hi,

thanks for those informations, it helped me a bit but now I come with two new questions: (should I ask them here?)
- Is there a way to use this CollectionPropertyDisplayMode only with some of my Collection properties? By the dataFactory?
- I want to use a specific editor for list object by using something like this :

<grids:PropertyEditor PropertyType="List<Person>">
   <grids:PropertyEditor.ValueTemplate>
      <DataTemplate>
         <TextBox/>
      </DataTemplate>
   </grids:PropertyEditor.ValueTemplate>
</grids:PropertyEditor>

but it seems not to be the right syntax. Is there a way I can do that?

Thanks!

AP

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Antoine,

1) Our TypeDescriptorFactory.GetPropertyModels method will look at CollectionPropertyDisplayMode and if it is not Default, and the property type is a collection, it will call the factory's CreateCollectionPropertyModel method instead of CreatePropertyModel.  Thus you could probably override CreateCollectionPropertyModel and if you wish to block a property from getting the collection treatment, examine the arguments to that method and return the value of a call to CreatePropertyModel instead.

2) For the custom property editor, you can't specify generics that easily in XAML.  This StackOverflow topic might give you ideas on how to specify a generic type in XAML, or you could use the ObjectType and PropertyName options for specifying the applicable properties instead:

https://stackoverflow.com/questions/10005187/how-to-reference-a-generic-type-in-the-datatype-attribute-of-a-datatemplate

Also note that your TextBox in the DataTemplate would need additional bindings to the value, read-only state, etc.  Our Property Editors topic in the documentation gives an example.


Actipro Software Support

Posted 6 years ago by Antoine Picard
Avatar

Hi !

Thanks for those two answers!

I only used your first point for now and it's working! But I don't have the delete (-) button, any idea why ? According to your documentation, it might be because my collection doesn't handle deletion but I'm sure it does.

Yeah the TextBox was just to give you an example of what I wanted. I know how xaml works.

AP

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

A delete button should show up on each list item if the ICollectionItemPropertyDescriptor created for the related item has its CanRemove property returning true.  You can see this in our "Collection New Items" QuickStart.

Our default ListItemPropertyDescriptor used for IList collections returns this for the CanRemove property:

return (!isCollectionReadOnly) && (list != null) && (!list.IsReadOnly) && (!list.IsFixedSize);

Are you sure your collection implements the basic IList interface and doesn't have IsReadOnly or IsFixedSize set?


Actipro Software Support

Posted 6 years ago by Antoine Picard
Avatar

Hello,

my collection implements IList interface but doesn't have IsReadOnly or IsFixedSize set.

My items in my collection don't have anything related to ICollectionItemPropertyDescriptor and I didn't override the CanRemove property.

I can't find either this code or any CanRemove property in your "Collection New Items" QuickStart. Neither any ListItemPropertyDescriptor. Not even in the entire solution.

Is there a new version of your samples ?

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Antoine,

I'm sorry, I should have also mentioned that our ExpandableCollectionConverter type converter that gets automatically injected for collection properties will create a ListItemPropertyDescriptor instance by default for each item in the collection.  That's how that gets put in place. 

By the way, our PropertyGridCollectionReadOnlyItems QuickStart shows how to override ExpandableCollectionConverter and apply some customized item property descriptors.  You might want to try something similar to see if the virtual ListItemPropertyDescriptor.CanRemove method is called and what it's returning.

Other than that, if you can't figure it out, please make a new simple smaple project that shows it happening and send that to our support address.  Remove any bin/obj folders from the sample you send, and rename the .zip file extension so it doesn't get spam blocked.  Thanks!


Actipro Software Support

Posted 6 years ago by Antoine Picard
Avatar

Hi,

so if I understand correctly, my Collection must inherits from ListItemPropertyDescriptor to have a CanRemove property ?

With the architecture of my project, it will be hard to use a converter only for a specific property. I don't want to use this converter on all objects of this type but only for one specific object.

And I can't really make a sample of my project because my collection class is inheriting from so many other classes, it will be a mess.

I'm feeling a bit stuck on this.

AP

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

No, I believe that as long as the collection is an IList and isn't read-only or fixed-size, then our built-in logic that makes a ExpandableCollectionConverter that should be applying the ListItemPropertyDescriptor to each item. 

This normally happens out-of-the-box if you allow expandable collections, but like I said, the PropertyGridCollectionReadOnlyItems QuickStart also shows how you can make an ExpandableCollectionConverter override to customize things.  You can do something similar just to verify if any of that is getting called.  

I'd need to have a simple sample project to debug to help you further in determining why it's not working automatically for your collection.


Actipro Software Support

Posted 6 years ago by Antoine Picard
Avatar

Hi,

just to update you, I chose to handle any collection, anything comming from IList will be handled.
I used your solution with the ExpandableCollectionConverter and it worked ! But it was a bit tricky and it wasn't really "beautiful" so I chose another path.

Thanks for your help !

Antoine

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Antoine,

I'm glad you got it working.  I'm curious what you had to do to get it going that wasn't working out of the box, assuming your collection implemented IList.


Actipro Software Support

Posted 6 years ago by Antoine Picard
Avatar

Hi,

I don't know but I just added EditableInline to my propertyGrid and the ExpandableCollectionConverter to my collection type (implementing IList) only with the CanRemove property always returning true and it worked. My collection doesn't directly implement IList but it implements other classes wich implements other classes, etc. and deeper it finally implements IList.

Hope it helped,

Antoine P

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Antoine,

The isCollectionReadOnly parameter mentioned in a previous post above comes from (CollectionPropertyDisplayMode != CollectionPropertyDisplayMode.EditableInline).  Thus isCollectionReadOnly will be false when you set EditableInline, which is good.

My guess is that your collection might directly or indirectly implement IList<T>, but note that interface doesn't always implement basic IList.  Are you sure that in your CanRemove you do a check that "yourcollectionref is IList" returns true?


Actipro Software Support

Posted 6 years ago by Antoine Picard
Avatar

Hi !

My collection implements ObservableCollection<T> wich implements Collection<T> wich implements both IList<T> and IList. In my CanRemove, I don't check anything as it's only used for this specific type so it looks like something like this

public override bool CanRemove
{
   get { return true; }
}

[Modified 6 years ago]

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.