-1
直到我爲兩個數組添加代碼之後,應用程序才正常工作。我有一些類級別的字符串:代碼更改後WPF程序將不會加載
string cFileName = "customer.txt";
string[] cName = new string[0];
string[] cPhone = new string[0];
而且我已將此添加到Window_Loaded
事件:
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
//read file on start
//ReadFile();
int counter = 0;
string line;
StreamReader custSR = new StreamReader(cFileName);
line = custSR.ReadLine();
while (custSR.Peek() != -1)
{
Array.Resize(ref cPhone, cPhone.Length + 1);
Array.Resize(ref cName, cName.Length + 1);
cPhone[cPhone.Length - 1] = line;
cName[cName.Length - 1] = line;
counter++;
//phoneComboBox.Items.Add(cPhone[cPhone.Length - 1]);
}
custSR.Close();
for (int i = 0; i < counter; i++)
{
phoneComboBox.Items.Add(cPhone[i]);
}
//focus when program starts
phoneComboBox.Focus();
}
我之所以//ReadFile()
是因爲我試圖把它作爲一個單獨的方法和呼叫到Window_Loaded
事件。我也嘗試從循環中輸出組合框。我以前沒有遇到過這種情況,無法弄清楚我所做的事情。
放嘗試捕捉周圍,看看你的例外是無聲 –
@GabrielGM如何才能嘗試捕捉幫助,如果它不會加載?我試過了,但仍然不會加載 – Jaqtaris
您是否檢查過'eventvwr'這個應用的特定錯誤?另外,你是否嘗試在調試器下運行應用程序? – sthotakura