-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
87 lines (73 loc) · 2.38 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace TreeTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private ObservableCollection<Object> Categories;
public MainWindow()
{
InitializeComponent();
Categories = GetCategoriesAndProducts();
tv.ItemsSource = Categories;
}
private ObservableCollection<Object> GetCategoriesAndProducts()
{
var CatColl = new ObservableCollection<Object>();
var FruitParts = new ObservableCollection<Part>();
var a1 = new Product("A1", "Apple");
a1.Parts = FruitParts;
var a2 = new Product("A2", "Avocado");
var a3 = new Product("A3", "Apriciot");
a3.Parts = FruitParts;
var ap = new ObservableCollection<Product>();
ap.Add(a1);
ap.Add(a2);
ap.Add(a3);
FruitParts.Add(new Part("Stem"));
FruitParts.Add(new Part("Seed"));
FruitParts.Add(new Part("Skin"));
var a = new Category("Alpha",ap);
var b1 = new Product("B1", "Banana");
b1.Parts = FruitParts;
var b2 = new Product("B2", "Beef");
var b3 = new Product("B3", "Buffalo");
var bp = new ObservableCollection<Product>();
bp.Add(b1);
bp.Add(b2);
bp.Add(b3);
var b = new Category("Beta", bp);
CatColl.Add(a);
CatColl.Add(b);
var pp = new Product("C4", "Califlower");
CatColl.Add(pp);
return CatColl;
}
private void cndAdd_Click(object sender, RoutedEventArgs e)
{
var p = new Product("X-001", "Extra");
foreach (Category cc in Categories)
{
if (cc.CategoryName == "Alpha")
{
cc.Products.Add(p);
}
}
}
}
}