InfoPointTemplateManager.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Com.FirmLib.Entity;
  2. using FWindSoft.Wpf.Controls;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Markup;
  12. using System.Windows.Media;
  13. using WPG;
  14. namespace Com.FirmLib.UI.Common
  15. {
  16. /// <summary>
  17. /// 信息点模板管理
  18. /// </summary>
  19. public class InfoPointTemplateParse : ITemplateParse
  20. {
  21. private static Dictionary<string, DataTemplate> m_RefDataTemplates = new Dictionary<string, DataTemplate>();
  22. static InfoPointTemplateParse()
  23. {
  24. ResourceDictionary dic = new ResourceDictionary();
  25. PropertyGrid gr = new PropertyGrid();
  26. dic.Source = new Uri("/Com.FirmLib.UI;component/Common/CellTemplates.xaml", UriKind.Relative);
  27. //dic.Source = new Uri("/TemplateLib;component/DataGrid/CellTemplates.xaml", UriKind.Relative);
  28. //dic.MergedDictionaries.Add(ResourceManager.DataGridCellTemplate);
  29. foreach (var key in dic.Keys)
  30. {
  31. DataTemplate tempTemplate = dic[key] as DataTemplate;
  32. if (tempTemplate != null)
  33. {
  34. m_RefDataTemplates.Add(key.ToString(), tempTemplate);
  35. }
  36. }
  37. }
  38. /// <summary>
  39. /// 根据信息点的信息去创建某值
  40. /// </summary>
  41. /// <returns></returns>
  42. public DataTemplate SelectTemplate(object ob)
  43. {
  44. var geDefinition = ob as EquipmentInfoPointItem;
  45. if (geDefinition == null)
  46. return CreateDefaultTemplate();
  47. //var id = geDefinition.CollectionCmptCode;
  48. //if(string.IsNullOrEmpty(id))
  49. // return CreateDefaultTemplate();
  50. string controlId = geDefinition.CollectionCmptCode;
  51. if (string.IsNullOrEmpty(geDefinition.CollectionCmptCode))
  52. {
  53. controlId = geDefinition.InputType;
  54. }
  55. if (controlId == "E1")
  56. {
  57. controlId = "Enum_D1";
  58. }
  59. DataTemplate template;
  60. if (!m_RefDataTemplates.TryGetValue(controlId, out template))
  61. {
  62. template = CreateDefaultTemplate();
  63. }
  64. return template;
  65. }
  66. private DataTemplate CreateDefaultTemplate()
  67. {
  68. DataTemplate temp = new DataTemplate();
  69. FrameworkElementFactory root = new FrameworkElementFactory(typeof(TextBlock));
  70. Binding binding = new Binding("Value");
  71. root.SetBinding(TextBlock.TextProperty, binding);
  72. temp.VisualTree = root;
  73. temp.Seal();
  74. return temp;
  75. }
  76. #region 构造解析器
  77. /// <summary>
  78. /// 创建模板解析器
  79. /// </summary>
  80. /// <returns></returns>
  81. public static CommonTemplateProvider CreateTemplateManager()
  82. {
  83. CommonTemplateProvider commonTemplate = new CommonTemplateProvider();
  84. InfoPointTemplateParse pasrse = new InfoPointTemplateParse();
  85. commonTemplate.Add(typeof(EquipmentInfoPointItem), pasrse);
  86. return commonTemplate;
  87. }
  88. #endregion
  89. }
  90. }