我得到这个未处理的异常错误:TargetInvocationException发生,但我完全不知道为什么
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in PresentationFramework.dll.
Additional information: Exception has been thrown by the target of an invocation.
这是我的代码的短。它是两个文本框的计算器,当用户按下WPF中的+, - ,/,x按钮时,它们应该一起成为新的答案。
public partial class MainWindow : Window
{
public string numberInString
{
get { return TextDoos.Text; }
set { TextDoos.Text = value; }
}
public MainWindow()
{
if(TextDoos.Text == "")
{
if(TextDoos2.Text == "")
{
RekenFunctie(TextDoos.Text, TextDoos2.Text);
}
}
}
}
public int RekenFunctie(string numberInString, string numberInString)
{
int antwoord;
int getal = Convert.ToInt32(numberInString);
int getal2 = Convert.ToInt32(numberInString2);
if (Buttons.IsPressed) // This is the + button, there are also -,x,/ buttons.
{
antwoord = getal + getal2;
return antwoord;
}
}
我不明白为什么它不工作...
TargetInvocationException总是有一个InnerException - 你应该看看那个以找出原因。 –