问题描述
我有一个WPF应用程序,它有一个属性网格。我正在使用类对象绑定属性网格(比如类名是mainclass)。 mainclass有一个属性APIConditions,它是另一个自定义类SearchAPIModel的Observable集合。 SearchAPIModel具有类KeyValues的observablecollection属性。我已使用属性网格的UI向APIConditions集合添加了一个项目。新添加的集合对象已成功保存。但我遇到的问题是,我能够将主类对象绑定到属性网格但是当我尝试打开应该在弹出窗口中打开的APIConditions属性时,应用程序崩溃并出现错误
PresentationFramework.dll中发生了'System.Reflection.TargetParameterCountException'类型的未处理异常
附加信息:参数计数不匹配。
有谁可以解释为什么会出现这个问题以及解决方法是什么?
提前致谢,
Rasheed
我尝试过:
请参阅课程如下。
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类
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类
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(""));
}
}
}
推荐答案
当调用的参数个数与预期的数量不匹配时引发的异常。
The exception that is thrown when the number of parameters for an invocation does not match the number expected.
查看面值的错误信息,你传递给的不是预期的。
你需要识别这条线在您开始寻找解决方案之前,会抛出错误。除非提供更多信息,否则我们不知道发生了哪一行或预期的内容。
一旦准备就绪,请用简明扼要的细节更新问题,样本代码,任何错误消息(包括内部异常详情)等,请点击改善问题以在问题中添加更多信息。
Looking at the error message at face value, what you are passing to not what is expected.
You need to identify the line that this error is thrown on before you can start looking for solutions. We don't know which line this occurs on or what is expected unless more information is provided.
Once you are ready update the question with clear and concise details, sample code, any error messages (including inner exception details), etc, please click on Improve question to add more info to the question.
这篇关于Wpf porpertygrid问题集合内的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!