private string AddCategory(string categoryAdd) { string methodName = "AddCategory"; TextInfo myTI = new CultureInfo("en-US", false).TextInfo; categoryAdd = myTI.ToTitleCase(categoryAdd); categoryAdd = categoryAdd.Trim(); if (!mCategoryDict.ContainsKey(categoryAdd) && categoryAdd != "") { Category category = new Category(); category.Name = categoryAdd; category.NewTotalAmount = 0; category.HaveTotalTextblock = false; mCategoryDict.Add(categoryAdd, category); Log(methodName, string.Format("Adding NEW Category: {0}", categoryAdd)); // Sort the comboBox items comboBoxCategory.Items.Clear(); List<string> tmpCatList = new List<string>(); tmpCatList = mCategoryDict.Keys.ToList(); tmpCatList.Sort(); comboBoxCategory.Items.Add(DEFAULT_CATEGORY_CAPTION); foreach (string cat in tmpCatList) { comboBoxCategory.Items.Add(cat); } } return categoryAdd; }
private void DisplayCategoryTotals(string category) { string methodName = "DisplayCategoryTotals"; string modCatName = category.Replace(' ', '_'); modCatName = modCatName.Replace("'", ""); // stkPanel.Name value can not contain apostrophy, so filter that out. Category cat = new Category(); cat = mCategoryDict[category]; Log(methodName, string.Format("Adding NEW control for category: {0}", category)); StackPanel stkPanel = new StackPanel(); stkPanel.Margin = new Thickness(20, 5, 5, 5); stkPanel.Orientation = Orientation.Horizontal; stkPanel.Name = string.Format("sp_{0}", modCatName); Label label = new Label(); label.Name = string.Format("lbl_{0}", modCatName); label.Content = string.Format("{0}: ", category); TextBlock textBlk = new TextBlock(); textBlk.Name = string.Format("tb_{0}", modCatName); //textBlk.Text = mCategoryDict[category].ToString(); textBlk.Margin = new Thickness(2, 5, 5, 5); //textBlk.DataContext = mCategoryDict[category]; Binding binding = new Binding(); // //binding.ElementName = textBlk.Text; binding.Source = cat; binding.Path = new PropertyPath("NewTotalAmount"); binding.StringFormat = "0.00"; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(textBlk, TextBlock.TextProperty, binding); // //textBlk.SetBinding(TextBlock.TextProperty, binding); stkPanel.Children.Add(label); stkPanel.Children.Add(textBlk); wpCategoryTotals.Children.Add(stkPanel); }
private void UpdateCategoryTotals(string category, float value) { string methodName = "UpdateCategoryTotals"; Category cat = new Category(); cat = mCategoryDict[category]; if (!cat.HaveTotalTextblock) { DisplayCategoryTotals(category); cat.HaveTotalTextblock = true; } float oldTotal = cat.NewTotalAmount; cat.NewTotalAmount += value; Log(methodName, string.Format("Category: {0} total was: $ {1} new amt: $ {2} new TOTAL: $ {3}", category, oldTotal, value, cat.NewTotalAmount)); }