我得到這個未處理的異常錯誤: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 - 你應該看看那個以找出原因。 –