I have a WPF application which has a property grid. I am binding the property grid with a class object (say the class name is "mainclass"). The "mainclass" has a property "APIConditions" which is an Observable collection of another custom class "SearchAPIModel". "SearchAPIModel" has a property of observablecollection of class "KeyValues". I have added an item to the "APIConditions" collection using the UI of property grid. The newly added object to the collection is saving successfully. But the problem I am facing is, I am able to bind the "main class" object to the property grid but when I am trying to open the "APIConditions" property which is supposed to open in a popupwindow, the application crashes with the error
"An unhandled exception of type 'System.Reflection.TargetParameterCountException' occurred in PresentationFramework.dll
Additional information: Parameter count mismatch."
Can anyone explain why this issue occurs and what is the solution for this ?.
Thanks in advance,
Rasheed
What I have tried:
Please see the classes as below.
[Serializable]
public class MainClass : INotifyPropertyChanged, INotifyCollectionChanged
{
private string _SelectText, _ID;
private ObservableCollection<searchapimodel> _APIConditions;
public event PropertyChangedEventHandler PropertyChanged;
public event NotifyCollectionChangedEventHandler CollectionChanged;
private void OnNotifyPropertyChanged(string propertyName)
{
var tmp = PropertyChanged;
if (tmp != null)
{
tmp(this, new PropertyChangedEventArgs(propertyName));
}
}
[CategoryAttribute("TextBox Details"), DefaultValueAttribute(true), DescriptionAttribute("ID of the TextBox control"), ReadOnly(true)]
public string ID
{
get { return _ID; }
set
{
if (_ID != value)
{
_ID = value;
}
}
}
[CategoryAttribute("LookupOption Details"), DefaultValueAttribute(true), DescriptionAttribute("Initial Text For Lookup And Nothing is Selected"), ReadOnly(false)]
public string SelectText
{
get { return _SelectText; }
set
{
if (_SelectText != value)
{
_SelectText = value;
}
}
}
[CategoryAttribute("LookupOption Details"), DefaultValueAttribute(true), DescriptionAttribute("Collection Of SearchAPIModel.")]
public ObservableCollection<searchapimodel> APIConditions
{
get { return _APIConditions; }
set
{
if (_APIConditions != value)
{
_APIConditions = value;
}
}
}
public MainClass()
{
this.SelectText = "[SELECT]";
this.ID = "";
this.APIConditions = new ObservableCollection<searchapimodel>();
}
}
SearchAPIModel class
[Serializable]
public class SearchAPIModel : INotifyPropertyChanged, INotifyCollectionChanged
{
private string _ConditionRow;
public event PropertyChangedEventHandler PropertyChanged;
public event NotifyCollectionChangedEventHandler CollectionChanged;
private ObservableCollection<keyvalues> _SearchTextList;
private void OnNotifyPropertyChanged(string propertyName)
{
var tmp = PropertyChanged;
if (tmp != null)
{
tmp(this, new PropertyChangedEventArgs(propertyName));
}
}
[CategoryAttribute("API Condition Details"), DefaultValueAttribute(true), DescriptionAttribute("ConditionRow")]
public string ConditionRow
{
get { return _ConditionRow; }
set
{
if (_ConditionRow != value)
{
_ConditionRow = value;
OnNotifyPropertyChanged("");
}
}
}
[CategoryAttribute("API Condition Details"), DefaultValueAttribute(true), DescriptionAttribute("SearchTextList")]
public ObservableCollection<keyvalues> SearchTextList
{
get { return _SearchTextList; }
set
{
_SearchTextList = value;
if (_SearchTextList != value)
{
_SearchTextList = value;
}
}
}
public SearchAPIModel()
{
this.ConditionRow = "";
this.SearchTextList = new ObservableCollection<keyvalues>();
}
}
KeyValues class
[Serializable]
public class KeyValues : INotifyPropertyChanged
{
private string _key, _Value;
[ReadOnly(false)]
public string Key
{
get { return _key; }
set { _key = value; }
}
[ReadOnly(false)]
public string Value
{
get { return _Value; }
set { _Value = value; }
}
public KeyValues()
{
Key = "";
Value = "";
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnNotifyPropertyChanged()
{
var tmp = PropertyChanged;
if (tmp != null)
{
tmp(this, new PropertyChangedEventArgs(""));
}
}
}