Hello,
I am using the XamPropertyGrid to allow the enduser to customize his environment.
When I try to use multiple CategorySortOrder entries I receive an exception: System.ArgumentException: Das Element wurde bereits hinzugefügt. Schlüssel im Wörterbuch: "Infragistics.Controls.Editors.CategorySortOrderAttribute". Hinzuzufügender Schlüssel: "Infragistics.Controls.Editors.CategorySortOrderAttribute".
Means: Key was already added.
Maybe I missunderstand the purpose of this attribute, but I guess it should allow multiple entries, because it's only usefull when you have multiple categories. The documentation leads me into the same direction.
Here is a small part of the class:
[CategorySortOrder("AutoStart", 1)] [CategorySortOrder("Mengenressourcen", 2)] // CategorySortOrder funktioniert nicht, weil das gleiche Element mehrfach hinzugefügt wird public sealed class UserConfig : ApplicationSettingsBase { [PropertySortOrder(1), Category("Baustellen"), Description("Die Adressdaten Strasse, Postleitzahl, Ort und die Koordinaten werden ein- bzw. ausgeblendet."), DisplayName("Adressdaten anzeigen"), DefaultSettingValue("False"), UserScopedSetting] public bool BaustelleAdressdaten { get{return (bool)this["BaustelleAdressdaten"];} set{this["BaustelleAdressdaten"] = value;} }} ThanksNikolaus Kern
Hello Nikolaus Kern,
Thank you for the description you have provided.
I've created a simple sample where the ClientViewModel's properties have the Category attribute for three different categories. The class uses CategorySortOrder attribute for two of the defined categories. Running the sample, I am not able to reproduce the raising of the exception that you have mentiond.
Could you please run the attached sample and try to modify it, so that i am able to investigate your scenario further ?
Please let me know if you have any other questions on this matter.
Hello Martin,
thanks for the quick replay. I adapted the example (16.1 instead of 16.2) and added my code till I could reproduze the problem.
The attached solution creates the exception.
It is clear that the exception is caused by my code - but I don't see it ;-)
Thanks
Niko
Hello Nikolaus,
This seems to be a bug in the framework’s ApplicationSettingsBase class which ClientViewModel derives from. The class is not correctly handling the scenario where multiple attributes of the same type are applied to a class derived from ApplicationSettingsBase class. You could prove this out in the sample by:
1. Removing our CategorySortOrder attribute from the ClientViewModel class and replacing it with an arbitrary framework attribute like so:
namespace PropertyGrid_MultiSelection_DoubleSet{ //[CategorySortOrder("Baustellen", 1)] //[CategorySortOrder("AutoStart", 2)] //[CategorySortOrder("Mengenressourcen", 3)] [ToolboxItemFilter("foo")] [ToolboxItemFilter("bar")] public sealed class ClientViewModel : ApplicationSettingsBase
2. Adding a line of test code to the sample’s MainWindow.InitializeSampleData method that accesses a property on the ClientViewModel:
public void InitializeSampleData() { var viewModel = new ClientViewModel(); bool b = viewModel.BaustelleAdressdaten; //viewModel.FirstName = "John"; //viewModel.MiddleName = "John"; //viewModel.LastName = "Doe"; //this.xamPropertyGrid1.CategorySortComparer = new CustomCategoryComparer(); this.xamPropertyGrid1.SelectedObject = viewModel; }
bool b = viewModel.BaustelleAdressdaten;
//viewModel.FirstName = "John"; //viewModel.MiddleName = "John"; //viewModel.LastName = "Doe"; //this.xamPropertyGrid1.CategorySortComparer = new CustomCategoryComparer(); this.xamPropertyGrid1.SelectedObject = viewModel; }
When you step over that line in debug you will see the same exception generated and the PropertyGrid is not involved at all.
thanks for the reply.
If I understand the response correctly there is no way to achieve the desired functionality with ApplicationsSettingBase.