Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. <DockPanel Grid.Row="2" Margin="0,6,0,0" Grid.RowSpan="5" Height="491" VerticalAlignment="Top">
  2. <DockPanel.Resources>
  3.  
  4. <src:TreeViewFilter x:Key="MyList" />
  5.  
  6. <HierarchicalDataTemplate DataType="{x:Type src:TreeViewParent}" ItemsSource="{Binding Path=OrderAttributes}">
  7. <TextBlock Text="{Binding Path=Name}" FontSize="16"/>
  8. </HierarchicalDataTemplate>
  9.  
  10. <HierarchicalDataTemplate DataType="{x:Type src:OrderAttribute}" ItemsSource="{Binding Path=OrderAttributes}">
  11. <TextBlock Text="{Binding Path=NameAndCount}" />
  12. </HierarchicalDataTemplate>
  13.  
  14. </DockPanel.Resources>
  15. <TreeView Name="treeView1" Height="490" Width="235" VerticalAlignment="Top" ItemsSource="{Binding Source={StaticResource MyList}, UpdateSourceTrigger=PropertyChanged}" TreeViewItem.Selected="treeViewFilter" />
  16. </DockPanel>
  17.  
  18. public class TreeViewFilter : ObservableCollection<TreeViewParent>
  19. {
  20. //three tree view parents that wont change
  21. public TreeViewParent allOrders;
  22. public TreeViewParent batchStatus;
  23. public TreeViewParent shippedOrders;
  24. static TreeViewFilter currentInstance1; //maybe set to null, can only create one instance!
  25.  
  26. public TreeViewFilter()
  27. {
  28.  
  29. currentInstance1 = this;
  30.  
  31. //Create and fill out all orders tree filter
  32. Add(allOrders = new TreeViewParent("All Orders", 0));
  33.  
  34. //Create and fill out batch status tree filter
  35. Add(batchStatus = new TreeViewParent("Batch Status", 0));
  36. int untouchedCount, batchReadyCount, errorCount;
  37.  
  38. OrderAttribute untouched = new OrderAttribute("Untouched", "Batch Status", 3, untouchedCount);
  39. OrderAttribute batchReady = new OrderAttribute("Batch Ready", "Batch Status", 3, batchReadyCount);
  40. OrderAttribute error = new OrderAttribute("Error", "Batch Status", 3, errorCount);
  41. batchStatus.OrderAttributes.Add(untouched);
  42. batchStatus.OrderAttributes.Add(batchReady);
  43. batchStatus.OrderAttributes.Add(error);
  44.  
  45. OrderManager currentInstance = OrderManager.getCurrentInstance();
  46. }
  47.  
  48. public static TreeViewFilter getCurrentInstance()
  49. {
  50. return currentInstance1;
  51. }
  52. }
  53.  
  54. public class Base
  55. {
  56. public int classIdentifier;
  57. }
  58.  
  59. public TreeViewParent(string name, int classIdent)
  60. {
  61. this._name = name;
  62. this._orderAttributes = new ObservableCollection<OrderAttribute>();
  63. classIdentifier = classIdent;
  64. currentInstance = this;
  65. }
  66.  
  67. public string _name;
  68.  
  69. public string Name { get { return _name; } }
  70.  
  71. ObservableCollection<OrderAttribute> _orderAttributes;
  72. public ObservableCollection<OrderAttribute> OrderAttributes
  73. {
  74. get { return _orderAttributes; }
  75. }
  76.  
  77. public static TreeViewParent getCurrentInstance()
  78. {
  79. return currentInstance;
  80. }
  81. }
  82.  
  83. public OrderAttribute(string name, string parent, int classIdent)
  84. {
  85. _name = name;
  86. parentFilter = parent;
  87. classIdentifier = classIdent;
  88. _orderAttributes = new ObservableCollection<OrderAttribute>();
  89. currentInstance = this;
  90. }
  91.  
  92. public OrderAttribute(string name, string parent, int classIdent, int count)
  93. {
  94. _name = name;
  95. parentFilter = parent;
  96. classIdentifier = classIdent;
  97. _count = count;
  98. currentInstance = this;
  99. }
  100.  
  101. string _name;
  102. public int _count = 0;
  103.  
  104. public string Name { get { return _name; } }
  105.  
  106. public string NameAndCount
  107. {
  108. get
  109. {
  110. if (_count == 0)
  111. {
  112. return _name;
  113. }
  114. else
  115. {
  116. return _name + " (" + _count + ")";
  117. }
  118. }
  119. }
  120.  
  121. ObservableCollection<OrderAttribute> _orderAttributes;
  122. public ObservableCollection<OrderAttribute> OrderAttributes { get { return _orderAttributes; } }
  123.  
  124. public static OrderAttribute getCurrentInstance()
  125. {
  126. return currentInstance;
  127. }
  128. }
  129.  
  130. public OrderAttribute : Base, INotifyPropertyChanged
  131. {
  132. public event PropertyChangedEventHandler PropertyChanged;
  133.  
  134. protected void FirePropertyChanged(string propertyName)
  135. {
  136. if (PropertyChanged != null)
  137. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  138. }
  139.  
  140. private int _count = 0;
  141.  
  142. public int Count
  143. {
  144. get { return _count; }
  145. set
  146. {
  147. if(_count != value)
  148. {
  149. _count = value;
  150. FirePropertyChanged("NameAndCount");
  151. }
  152. }
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement