private void RebuildListView() { Workspace.Category selected_item = null; if (categoriesListView.SelectedItem != null) { selected_item = (categoriesListView.SelectedItem as CategoriesListItem).Category; } categoriesListView.Items.Clear(); foreach (Workspace.Category category in Workspace.Instance.Categories) { CategoriesListItem item = new CategoriesListItem(); item.Color = category.Color.ToString(); item.Title = category.Title; item.Category = category; categoriesListView.Items.Add(item); } if (selected_item != null) { int idx = Workspace.Instance.Categories.IndexOf(selected_item); if (idx >= 0) { categoriesListView.SelectedIndex = idx; } } }
private void addButton_Click(object sender, RoutedEventArgs e) { Workspace.Category cat = new Workspace.Category(); cat.Color = Color.FromArgb(255, 255, 0, 0); cat.Title = "New category"; Workspace.Instance.AddCategory(cat); RebuildListView(); }
private void OptionsButton_ContextMenuOpening(object sender, ContextMenuEventArgs e) { addNotesMenuItem.IsEnabled = (mTask.Notes == null); // Rebuild our context menu while (categoryMenuItem.Items.Count > 2) { categoryMenuItem.Items.RemoveAt(0); } for (int i = -1; i < Workspace.Instance.Categories.Count; ++i) { Workspace.Category cat = (i >= 0) ? Workspace.Instance.Categories[i] : null; MenuItem item = new MenuItem(); item.Header = (i < 0) ? "None" : cat.Title; item.Tag = (Object)i; item.IsCheckable = true; item.IsChecked = mTask.CategoryIndex == i; item.Click += CategoryMenuItem_Click; categoryMenuItem.Items.Insert(i + 1, item); } }