private void Window_Loaded(object sender, RoutedEventArgs e) { // 讀檔 string[] lines = System.IO.File.ReadAllLines(@"C:\temp\data.txt"); int total = 0; // 逐行產生元件 foreach (string line in lines) { // 用符號分隔 string[] parts = line.Split('|'); // 建立元件 todo item = new todo(); item.ItemDate = parts[0]; item.ItemName = parts[1]; item.ItemMoney = parts[2]; int itemPrice = int.Parse(parts[2]); total += itemPrice; // 放入到 StackPanel TodoItemList.Children.Add(item); // 顯示總金額 Total.Text = total.ToString(); } }
private void AddMark_MouseDown(object sender, MouseButtonEventArgs e) { // 建立原件 todo item = new todo(); // 放入到 StackPanel TodoItemList.Children.Add(item); }