RecipeSelectDialog.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Aitex.Core.UI.View.Common;
  15. using System.Xml;
  16. namespace Aitex.Core.UI.Dialog
  17. {
  18. /// <summary>
  19. /// Interaction logic for RecipeSelectDialog.xaml
  20. /// </summary>
  21. public partial class RecipeSelectDialog : Window
  22. {
  23. string _recipeList;
  24. public RecipeSelectDialog(string recipeList)
  25. {
  26. _recipeList = recipeList;
  27. InitializeComponent();
  28. Loaded += new RoutedEventHandler(RecipeSelectDialog_Loaded);
  29. }
  30. /// <summary>
  31. /// load recipe file list
  32. /// </summary>
  33. /// <param name="sender"></param>
  34. /// <param name="e"></param>
  35. void RecipeSelectDialog_Loaded(object sender, RoutedEventArgs e)
  36. {
  37. XmlDocument doc = new XmlDocument();
  38. doc.LoadXml(_recipeList);
  39. CreateTreeViewItems(doc.DocumentElement, this.treeView1);
  40. }
  41. /// <summary>
  42. /// Create TreeViewItems
  43. /// </summary>
  44. /// <param name="curElementNode"></param>
  45. void CreateTreeViewItems(XmlElement curElementNode, ItemsControl itemsControl)
  46. {
  47. foreach (XmlElement ele in curElementNode.ChildNodes)
  48. {
  49. if (ele.Name == "File")
  50. {
  51. string fileName = ele.Attributes["Name"].Value;
  52. fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
  53. TreeViewFileItem item = new TreeViewFileItem(ele.Attributes["Name"].Value);
  54. item.Tag = ele.Attributes["Name"].Value;
  55. item.ToolTip = ele.Attributes["Name"].Value;
  56. itemsControl.Items.Add(item);
  57. }
  58. else if (ele.Name == "Folder")
  59. {
  60. string folderName = ele.Attributes["Name"].Value;
  61. folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
  62. TreeViewFolderItem item = new TreeViewFolderItem(folderName);
  63. item.Tag = ele.Attributes["Name"].Value;
  64. CreateTreeViewItems(ele, item);
  65. item.IsExpanded = false;
  66. itemsControl.Items.Add(item);
  67. }
  68. }
  69. }
  70. /// <summary>
  71. /// Selected recipe file
  72. /// </summary>
  73. public string SelectedRecipe
  74. {
  75. get
  76. {
  77. var file = treeView1.SelectedItem as TreeViewFileItem;
  78. if (file != null)
  79. return file.FileName;
  80. return string.Empty;
  81. }
  82. }
  83. /// <summary>
  84. /// On click cancel button
  85. /// </summary>
  86. /// <param name="sender"></param>
  87. /// <param name="e"></param>
  88. private void btnCancel_Click(object sender, RoutedEventArgs e)
  89. {
  90. DialogResult = false;
  91. Hide();
  92. }
  93. /// <summary>
  94. /// On click ok button
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void btnOK_Click(object sender, RoutedEventArgs e)
  99. {
  100. DialogResult = true;
  101. Close();
  102. }
  103. }
  104. }